![](/img/trans.png)
[英]In PHP, move_uploaded_file uploads files to one directory, but fails to upload for a different directory?
[英]How to define upload directory when uploading files with php move_uploaded_file
我正在尝试将多个文件上传到我的网站。我正在直接上传到我的子域名。 我有以下代码:
<?php
$valid_formats = array("jpg", "png", "gif", "zip","jpeg", "bmp");
$max_file_size = 1024*100; //100 kb
$path = "uploads/"; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {
if ($_FILES['files']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['files']['error'][$f] == 0) {
if ($_FILES['files']['size'][$f] > $max_file_size) {
$message[] = "$name is too large!.";
continue; // Skip large files
}
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
$count++; // Number of successfully uploaded file
echo "file has probably been uploaded";
}
}
}
}
?>
当我尝试上传文件时,我得到了failed to open stream: No such file or directory
并且Unable to move....file has probably been uploaded
消息。 还有许多其他问题,可能的解决方案,但我想问如何定义上传的路径,因为我认为我错了。 任何其他提示如何获得这项工作将是有帮助的。
如果你在Windows中授予它写文件的权限。
找到文件夹>右键单击>属性。 并且在安全性方面允许写入和读取。
通用设定给大家
你的道路将是
$ path =“./ uploads /”;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.