Upload a file on my Owncloud server with PHP Upload a file on my Owncloud server with PHP curl curl

Upload a file on my Owncloud server with PHP


I was having an issue with an upload to owncloud as well. Had the same symptoms, the command line curl works, but not the PHP curl call.

Thanks to your post I was able to get it working. Here is what works for me

// upload backup$file_path_str = '/tmp/' . date('Ymd') . '.tar.gz';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'http://server/remote.php/webdav/backups/' . basename($file_path_str));curl_setopt($ch, CURLOPT_USERPWD, "user:pass");curl_setopt($ch, CURLOPT_PUT, 1);$fh_res = fopen($file_path_str, 'r');curl_setopt($ch, CURLOPT_INFILE, $fh_res);curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path_str));curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary$curl_response_res = curl_exec ($ch);fclose($fh_res);

The differences are:

  • CURLOPT_PUT instead of CURLOPT_CUSTOMREQUEST
  • CURLOPT_INFILE and CURLOPT_INFILESIZE instead of CURLOPT_POSTFIELDS

Thanks for your help.//