【发布时间】:2015-02-09 18:09:09
【问题描述】:
在将 zip 文件上传到我的服务器时遇到问题。 move_uploaded_file 函数每次都失败。我不明白这个问题。文件夹权限为 777,文件大小约为 2 Mb。
<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?
-
您有错误报告吗?
-
这是$final_path "../uploads/H725/2015_02_09_09_26/Archive.zip" 的内容是正确的,并且在服务器上创建两个文件夹没有问题
-
你能告诉我对于大文件我必须更改 php.ini 的哪个选项吗??