使用PHP将zip文件夹上载到远程服务器?

使用PHP将zip文件夹上载到远程服务器?,php,curl,Php,Curl,我试图使用PHP CURL将zip文件夹上载到远程服务器上,但我不知道为什么上载到远程服务器上的zip文件夹/文件是空的 基本上,文件是上传的(有些方式),但当我查看上传的文件夹时,它显示为0字节,但zip文件夹中有700字节的文件 这是我的密码: <form enctype="multipart/form-data" encoding="multipart/form-data" method="post" action="myfile.php"> <input name=

我试图使用PHP CURL将zip文件夹上载到远程服务器上,但我不知道为什么上载到远程服务器上的zip文件夹/文件是空的

基本上,文件是上传的(有些方式),但当我查看上传的文件夹时,它显示为
0字节
,但zip文件夹中有
700字节
的文件

这是我的密码:

<form enctype="multipart/form-data" encoding="multipart/form-data" method="post" action="myfile.php">
  <input name="uploadedfile" type="file" value="choose">
  <input type="submit" value="Upload">
</form>



<?php
if (isset($_FILES['uploadedfile']) ) {
    $filePath  = $_FILES['uploadedfile']['tmp_name'];

    $POST_DATA = array(
        'file' => '@'.  realpath($filePath)
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'http://remotesite/handle.php');
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $POST_DATA);
    $response = curl_exec($curl);
    curl_close ($curl);

     if($errno = curl_errno($curl)) {
        $error_message = curl_strerror($errno);
        echo "cURL error ({$errno}):\n {$error_message}";
    } else {
        echo "<h2>File Uploaded</h2>";
    }
}
?>

这是我的handle.php代码:

<?php
$encoded_file = $_POST['file'];
$decoded_file = base64_decode($encoded_file);
/* Now you can copy the uploaded file to your server. */
file_put_contents('subins.zip', $decoded_file);
?>

有人能告诉我我错过了什么或做错了什么吗


提前感谢,

当你上传一个文件到php时,它会创建一个临时复制的文件,当脚本结束时,这些文件会消失。您需要将上载的文件存储到其他位置:

Handle.php:

if ($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
  } else {
      // Move the file to the desired directory
      move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
  }
if($\u文件[“文件”][“错误”]>0){
回显“返回代码:”.$\u文件[“文件”][“错误”]。
”; }否则{ //将文件移动到所需目录 移动上传的文件($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\; echo“存储在:“.”upload/“$\u文件[”文件“][”名称“]; } }
它是否适用于其他文件类型?检查以确保服务器没有遇到磁盘配额问题。您正在handle.php中查看$POST['file'],但输入似乎被称为uploadefile。不管怎样,您将内容放入zip文件中,但从未尝试将其“解压缩”到文件夹中…是否存在将上载的文件移动到根文件夹而不是将其保留在上载文件夹中的方法?例如,将其移动到公共的html文件夹?我确实尝试了重命名();我还尝试了
move_上传的文件($_文件[“文件”][“tmp_名称”],“./”$_文件[“文件”][“名称])显示所有其他代码,但不会将上载的文件夹移动到公共html。有什么建议吗?@shell您可以将完整路径/home/user/public_html作为示例,或者以更灵活的方式
move_上传的_文件($_文件[“文件”][“tmp_名称”]、realpath(“../”)。$_文件[“文件”][“名称”]
谢谢,但仍然没有将文件移动到公共\u html!它确实将文件上载到上载文件夹,但没有复制或移动到公共\u html!@shell Try
移动\u上载的文件($\u FILES[“file”][“tmp\u name”],“/home/user/public\u html”。$\u FILES[“file”[“name”]);//调整到所需的完整路径
仍然没有将其移动到公共位置)html。我也确保了路径是正确的。。。是否有办法将上传文件夹中的任何内容移动到公共html?