WAMP: failed to open stream: No such file or directory

可紊 提交于 2019-12-08 06:35:45

问题


I'm trying to upload a file using PHP. My HTML page with the form is stored at

C:\wamp\www\myproject\upload.html

PHP page is

 C:\wamp\www\myproject\upload.php, 

and the file I'm trying to upload is

C:\wamp\www\myproject\openoffice.txt.

When I try to upload the file, I get the following error:

Warning: move_uploaded_file(/uploads/openoffice.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\myproject\upload.php on line 40

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpF66A.tmp' to '/uploads/openoffice.txt' in C:\wamp\www\myproject\upload.php on line 40 Problem: could not move file to destination directory

Here are lines 40-43 of upload.php:

if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) {
    echo 'Problem: could not move file to destination directory';
    exit;
}

The fact that it's looking in upload.php instead of the folder that it's in makes me wonder whether it's a server error or an issue with my PHP.

I Googled and got this advice but I don't know if it's the right advice, or how to implement it. Help?


回答1:


You should be supplying a file system path for $upFile, not a web based path. try using the full system path to you your uploads directory like C:\path\to\uploads\openoffice.txt. Unless of course youre actually trying to place the file in C:\uploads...




回答2:


Try this code

$imgName = time();
$imgPath = BASEPATH."../uploads/".$imgName;
$image = base_url().'uploads/'.$imgName;
move_uploaded_file($_FILES["file"]["tmp_name"],$imgPath.".jpg");
$imageNew =$imgName;

Where uploads is the folder name just rename it with your folder name or make your folder as name it as uploads. Its working code.

Thanks




回答3:


Give your '/uploads/' folder where you are going to upload your file. 777 rights. Give full permission to that directory.



来源:https://stackoverflow.com/questions/4231282/wamp-failed-to-open-stream-no-such-file-or-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!