当我尝试上传文件时,这个php脚本会重新调整错误。我在win xp机器上使用XAMPP。我相信我已正确设置了共享权限。
脚本:
//For images
if (isset($_FILES['image300x100']) && !empty($_FILES['image300x100']['tmp_name'])) {
$name = $_FILES['image300x100']['name']; // getting the name of the file
$tempName = $_FILES['image300x100']['tmp_name']; // getting the temporary file name.
$allowedExt = array('jpg', 'jpeg', 'png', 'gif' );// specifying the allowed extentions
$a = explode('.', $name);
$fileExt = strtolower(end($a)); unset($a);//
$fileSize = $_FILES['image300x100']['size'];
$filePath = "";
switch($category){
case 1 : $filePath = "c:/www/Perspect/categories/politics/articleImages"; break;
//etc etc etc
}
$path = $filePath;
} else{
$errors[] = 'no file selected';
}
$moveResult = move_uploaded_file($tempName, $filePath);
离开,因为错误是:
Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in C:\www\Dev\admin\addNewArticle.php on line 62
Warning: move_uploaded_file(): Unable to move 'C:\Server\XAMPP\tmp\php62C.tmp' to 'c:/www/Dev/categories/bla/articleImages' in C:\www\Dev\admin\addNewArticle.php on line 62
我从我认为是正确路径的路径中删除了c:/
,但结果是:
temp nameC:\Server\XAMPP\tmp\php62E.tmp filepath
www/Dev/categories/bla/articleImages
Warning: move_uploaded_file(www/Dev/categories/bla/articleImages): failed to open stream: No such file or directory in C:\www\Dev\admin\addNewArticle.php on line 62
Warning: move_uploaded_file(): Unable to move 'C:\Server\XAMPP\tmp\php62E.tmp' to 'www/Dev/categories/bla/articleImages' in C:\www\Dev\admin\addNewArticle.php on line 62
非常感谢任何帮助
答案 0 :(得分:1)
您需要指定目标文件名,例如:
$filePath = "c:/www/Perspect/categories/politics/articleImages/file.png";
或者,您可以生成随机名称。
答案 1 :(得分:1)
如错误所示,第二个参数是目录,而不是文件。您需要将文件名添加到目标路径。