1

当我尝试上传文件时,此 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

非常感谢任何帮助

4

2 回答 2

1

您需要指定目标文件名,例如:

$filePath = "c:/www/Perspect/categories/politics/articleImages/file.png";

或者,您可以生成一个随机名称。

于 2013-09-17T16:01:09.130 回答
1

正如错误所说,第二个参数是目录,而不是文件。您需要将文件名添加到目标路径。

于 2013-09-17T16:01:42.193 回答