PHP 上传文件未保存且未显示错误
PHP uploaded file is not saved and no error is shown
我不知道我的代码是否正确,但是发送时一切都表明成功..
我的表格
<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'];
}
}
?>
我得到的消息是 "Sent",但是当我去检查时,文件夹文件是空的 :s
我的文件夹结构是:
/files - Here is directory where the files will come
index.php - My form
upload.php - My Logic
我在您的代码中看到的一个问题是您没有为 "moved" 文件指定名称:
这一行:
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”路径是正确并且没有权限问题。
如果您的目标文件夹没有写入权限,也会出现同样的问题。
使用此命令更改:
chmod 775 [folder-name]
我不知道我的代码是否正确,但是发送时一切都表明成功..
我的表格
<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'];
}
}
?>
我得到的消息是 "Sent",但是当我去检查时,文件夹文件是空的 :s
我的文件夹结构是:
/files - Here is directory where the files will come
index.php - My form
upload.php - My Logic
我在您的代码中看到的一个问题是您没有为 "moved" 文件指定名称:
这一行:
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”路径是正确并且没有权限问题。
如果您的目标文件夹没有写入权限,也会出现同样的问题。
使用此命令更改:
chmod 775 [folder-name]