0

我收到此错误,我不确定如何清除它。不确定它是否在我的 WAMP 上,如果是,我有两个 ini 文件,开发和生产,我应该去哪里看?

( ! ) Warning: move_uploaded_file(uploadedFiles/gal2.jpg): failed to open stream: No such file or directory in C:\wamp\www\fileupload.php on line 20
Call Stack
#   Time    Memory  Function    Location
1   0.0007  257960  {main}( )   ..\fileupload.php:0
2   0.0015  303448  move_uploaded_file ( )  ..\fileupload.php:20

( ! ) Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php71A.tmp' to 'uploadedFiles/gal2.jpg' in C:\wamp\www\fileupload.php on line 20
Call Stack
#   Time    Memory  Function    Location
1   0.0007  257960  {main}( )   ..\fileupload.php:0
2   0.0015  303448  move_uploaded_file ( )  ..\fileupload.php:20

代码如下:

$desiredPath = 'uploadedFiles/';
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
    print "Picture Info"."<br>";
    print_r($_FILES['picture']);

    if (move_uploaded_file($_FILES['picture']['tmp_name'], $desiredPath.$_FILES['picture']['name']))
    {
        print 'File Upload Successful';
        print '<div>';
        print '<img width="300px" src="'.$desiredPath.$_FILES['picture']['name'].'">';
        print '</div>';
    }
    else
    {
        print 'File Upload Failed with error code: '.$_FILES['picture']['error'];
    }
}
4

1 回答 1

1

你的代码:

$desiredPath = 'uploadedFiles/';

在将文件移动到该目录之前,您是否测试过该目录是否存在?下面的代码:

if(!file_exists($desiredPath)) {
    mkdir($desiredPath, 0755, true);
}

这只是一个建议。我试图自己创建一个上传脚本,那一小段代码解决了我所有的问题

于 2013-10-05T15:45:45.413 回答