Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
让PHP上传到NextCloud文件夹_Php - Fatal编程技术网

让PHP上传到NextCloud文件夹

让PHP上传到NextCloud文件夹,php,Php,这似乎是一个奇怪的问题,但我正试图让我的网站上传用户输入到我的Nextcloud实例文件夹中的文件。因此,我可以与团队中的其他人分享 我还没有找到任何关于如何做到这一点的方法。我已经创建了一个文件夹并为其创建了一个共享链接 我尝试使用的代码是: $file = $_FILES['fileToUpload']; $fileName = $file['name']; $fileTmpName = $file['tmp_name']; $fileSize = $file['size']; $file

这似乎是一个奇怪的问题,但我正试图让我的网站上传用户输入到我的Nextcloud实例文件夹中的文件。因此,我可以与团队中的其他人分享

我还没有找到任何关于如何做到这一点的方法。我已经创建了一个文件夹并为其创建了一个共享链接

我尝试使用的代码是:

$file = $_FILES['fileToUpload'];

$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];

$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));

$allowed = array('pdf', 'docx', 'doc');

if (in_array($fileActualExt, $allowed)) {
 if ($fileError === 0) {
  if ($fileSize < 1000000) {
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, "https://files.devplateau.com/nextcloud/index.php/s/jfbavtp4q6UWNlR");
    curl_setopt($c, CURLOPT_USERPWD, "username:password");
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_PUT, true);
    //curl_setopt($c, CURLOPT_INFILESIZE, filesize($file));

    $fp = fopen($file, "r");
    curl_setopt($c, CURLOPT_INFILE, $fp);

    curl_exec($c);

    curl_close($c);
    fclose($fp);
   } else {
      echo "Your file is too big!";
   }
 } else {
   echo "There was an error uploading your file!";
 }
 } else {
   echo "You cannot upload files of this type!";
 }
我明白第一个警告的意思。我只是不知道如何将数组转换成fopen可以使用的东西。那么我真的不明白另一个警告是什么意思


有人能帮我完成这项工作吗?或者找一个更好的方法来完成这项工作吗?

您必须将url更改为:remote.php/dav/files/user/path/to/file

这些错误消息告诉您需要知道的一切
$file
在这里设置
$file=$\u files['fileToUpload'即,您已将其设置为$_FILES数组,因此出现错误消息try
$fp=fopen($fileTmpName,“r”)也许你会更接近你想要的achieve@RiggsFolly谢谢你的回复!这消除了错误,我感谢你的帮助。但是,它不会将文件上载到我想要它的Nextcloud中的文件夹。你知道为什么会这样吗?
Warning: fopen() expects parameter 1 to be a valid path, array given...

Warning: curl_setopt(): supplied argument is not a valid File-Handle resource...

Warning: fclose() expects parameter 1 to be resource, boolean given...