我正在尝试将多个文件上传到我的网站。我正在直接上传到我的子域名。我有以下代码:
<?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
条消息。还有许多其他问题,可能的解决方案,但我想问如何定义上传的路径,因为我认为我错了。任何其他提示如何获得这项工作都会有所帮助。
答案 0 :(得分:0)
如果您的in Windows授予其写入文件的权限。
找到文件夹&gt;右键单击&gt;属性。并且在安全性方面允许写入和读取。
为每个人设定的通用目的
你的路径将是
$ path =&#34; ./ uploads /&#34 ;;