1

I searched for working example to upload a file to a new installed nextcloud.

Can anybody provide some sample code?

I found one script usint sabre dav but this only results in App not installed error.

Another script used curl_exec gets file not found from nextcloud:

$fp = fopen("test.jpg", "r");

$c = curl_init();
curl_setopt($c, CURLOPT_URL, "https://mcloud.XXXX.at/index.php/s/fo7W3MMRnas9B3G");
curl_setopt($c, CURLOPT_USERPWD, "xxx:yyyy"); 
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_PUT, true); 
curl_setopt($c, CURLOPT_INFILESIZE, filesize("test.jpg"));
curl_setopt($c, CURLOPT_INFILE, $fp);
$ret = curl_exec($c);

EDIT: with sabre DAV i also tested the following code without success:

include 'vendor/autoload.php';

$settings = array(
    'baseUri' => 'https://XXXXXXXXXXXXXXX.at/remote.php/dav',
    'userName' => 'test1',
    'password' => 's8R87-JCZN6-tf3Eb-aHLyj-zPzKW'
);

$client = new Sabre\DAV\Client($settings);

// Upload a file
$upload_result = $client->request('PUT', 'test-upload.txt', 'This will be written to the txt file');

the result with sabre dav was always html response with "App not installed" message

Jack
  • 59
  • 7
  • Have a look at this: http://sabre.io/dav/davclient/ Never used but by the looks of it seems like it is the right tool for the job. – Paperclip Feb 20 '19 at 22:02
  • @Klamberext: i already tried it wihout success (just edited my post) – Jack Feb 21 '19 at 06:09
  • Review this post https://stackoverflow.com/questions/59328246/uploading-a-file-to-nextcloud-with-php-curl-in-postman-but-the-file-uploaded-is/68993056#68993056 – Doberon Aug 31 '21 at 04:54

1 Answers1

1

already found the solution. the plai php-curl works but i had to change the URL to:

curl_setopt($c, CURLOPT_URL, "https://XXXXXXXX/remote.php/webdav/SUBPATH/test.jpg");
Jack
  • 59
  • 7