將zip文件上傳到我的服務器時出現問題。 每次都會失敗move_uploaded_file函數。我不明白這個問題。文件夾權限爲777,文件大小約爲2 Mb。使用POST請求在php中上傳文件
<html>
<body>
<form action="../API/upload_zip.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Zip" name="submit">
</form>
</body>
</html>
-
<?php
$target_dir = "../uploads/";
$machineID="H725";
$path=$target_dir.$machineID;
if (!file_exists($path))
{
if(!mkdir($path, 0777, true)) die('Failed to create folders 1...');
chmod($path, 0777);
}
$pathWithData= $path."/".date("Y_m_d_h_i");
if (!file_exists($pathWithData))
{
if(!mkdir($pathWithData, 0777, true)) die('Failed to create folders 2...');
chmod($pathWithData, 0777);
}
$final_path = $pathWithData ."/". basename($_FILES["fileToUpload"]["name"]);
echo "PATH: ".$final_path."<br>";
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $final_path))
{
echo "<br>The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
}
else
{
echo "<br>Sorry, there was an error uploading your file.";
}
?>
您是否獲得許可被拒絕的錯誤還是其他什麼東西?另外,它是否發生在一個小文件上,例如10kb? – 2015-02-09 18:12:39
你有錯誤報告? – AbraCadaver 2015-02-09 18:14:14
這是$ final_path「../uploads/H725/2015_02_09_09_26/Archive.zip」的內容,是正確的,並且在服務器上創建這兩個文件夾沒有問題 – Paolo 2015-02-09 20:29:14