我不知道我的代码是否正确,但发送时一切都表示成功..
我的表格
<form action="upload.php" method="POST" enctype="multipart/form-data">
File: <input type="file" name="file" />
<input type="submit" name="submit" value="Go" />
</form>
我的上传文件
<?php
if($_FILES['file']['name'])
{
if(!$_FILES['file']['error'])
{
$valid_file = true;
if($_FILES['file']['size'] > (1024000)) //can't be larger than 1 MB
{
$valid_file = false;
$message = 'Oops! Your file\'s size is to large.';
}
if($valid_file)
{
/
if(move_uploaded_file($_FILES['file']['tmp_name'],'/files')){
echo "Sent";
}else{
echo "~Error~";
}
}
}
//if there is an error...
else
{
$message = 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
}
}
?>
我得到的消息是“已发送”,但当我去检查时,文件夹文件为空:s
我的文件夹结构是:
/files - Here is directory where the files will come
index.php - My form
upload.php - My Logic
答案 0 :(得分:3)
我在您的代码中看到的一个问题是您没有为“已移动”文件指定名称:
这一行:
move_uploaded_file($_FILES['file']['tmp_name'],'/files')
应改为:
move_uploaded_file($_FILES['file']['tmp_name'],'/files/'.'sampleName'.$extension);// extension is the extension of the file.
我仍然认为您的'/ files'路径正确且没有权限问题。
答案 1 :(得分:1)