WAMP:无法打开流:没有这样的文件或目录
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?
我正在尝试使用PHP上传文件。 我的带有表单的HTML页面存储在 p>
C:\ wamp \ www \ myproject \ upload.html
code> pre>
PHP页面是 p>
C:\ wamp \ www \ myproject \ upload.php,
code> pre>
和 我要上传的文件是 p>
C:\ wamp \ www \ myproject \ openoffice.txt。
code> pre>
当我尝试上传文件时,出现以下错误: p>
警告 strong>:move_uploaded_file(/uploads/openoffice.txt )[function.move-uploaded-file]:无法打开流:第40行的C:\ wamp \ www \ myproject \ upload.php中没有此类文件或
目录 p>
警告 strong>:move_uploaded_file()[function.move-uploaded-file]:无法在C中将'C:\ wamp \ tmp \ phpF66A.tmp'移动到'/uploads/openoffice.txt'
:\ wamp \ www \ myproject \ upload.php第40行问题:无法将
文件移动到目标目录 p>
blockquote>
以下是上传的第40-43行 .php: p>
if(!move_uploaded_file($ _ FILES ['userfile'] ['tmp_nam e'],$ upfile)){
echo'问题:无法将文件移动到目标目录';
退出;
}
code> pre>
事实 它正在查看upload.php而不是它所在的文件夹让我想知道它是服务器错误还是我的PHP问题。 p>
我用Google搜索并得到这个建议,但我不知道这是否是正确的建议,或者 如何实现它。 帮助? p>
div>
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
...
Give your '/uploads/' folder where you are going to upload your file. 777 rights. Give full permission to that directory.
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