使用PHP将文件上载到web目录
我试图从一个网页创建一个简单的上传应用程序:localhost/test.html。我发现以下错误: 警告:移动上传的文件(test/bluehills.jpg):无法打开流: 第11行的C:\wamp\www\test.html中没有这样的文件或目录 及 警告:移动\u上载的\u文件():无法移动'C:\wamp\tmp\php376.tmp' 到第11行C:\wamp\www\test.html中的“test/bluehills.jpg” 这是我的密码使用PHP将文件上载到web目录,php,html,Php,Html,我试图从一个网页创建一个简单的上传应用程序:localhost/test.html。我发现以下错误: 警告:移动上传的文件(test/bluehills.jpg):无法打开流: 第11行的C:\wamp\www\test.html中没有这样的文件或目录 及 警告:移动\u上载的\u文件():无法移动'C:\wamp\tmp\php376.tmp' 到第11行C:\wamp\www\test.html中的“test/bluehills.jpg” 这是我的密码 <html> <
<html>
<form enctype="multipart/form-data" action="test.html" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
<html>
<?php
$target = "test/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else {
echo "Uploading Error.";
}
请选择一个文件:
目录test
可能不存在。将这些行添加到代码中
if (file_exists('test/')) echo 'Ok it wasn\'t that';
else echo 'Um, create a directory called test here: '.dirname(__FILE__);
确保脚本所在的目录中存在atest/
目录,然后可以使用
$out = dirname(__FILE__) . '/' . $_FILES['uploaded']['name'];
move_uploaded_file($_FILES['uploaded']['tmp_name'], $out);
通过FTP客户端将目录权限(CHMOD)更改为777
(读、写、为所有者、组、公共执行)。谢谢,我测试了它,它说没有目录。但是文件不应该以相同的方式工作吗?ie./test.htmlscratch,我现在看到它必须是一个文件夹。谢谢你的帮助。谢谢@bborisovs。这也有一个可预测的行为,而不是依赖于getcwd()
。。。