我上傳的形式是爲什麼我的上傳腳本不能工作?沒有錯誤
<form action="accept-file.php" method="post" enctype="multipart/form-data">
Your Photo: <input type="file" name="photo" size="25" />
<input type="submit" name="submit" value="Submit" />
</form>
而且accept-file.php
是
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
//if they DID upload a file...
if($_FILES['photo']['name'])
{
//if no errors...
if(!$_FILES['photo']['error'])
{
//now is the time to modify the future file name and validate the file
$new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file
if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
{
$valid_file = false;
$message = 'Oops! Your file\'s size is to large.';
}
//if the file has passed the test
if($valid_file)
{
//move it to where we want it to be
move_uploaded_file($_FILES['photo']['tmp_name'], 'uploads/'.$new_file_name);
$message = 'Congratulations! Your file was accepted.';
}
}
//if there is an error...
else
{
//set that to be the returned message
$message = 'Ooops! Your upload triggered the following error: '.$_FILES['photo']['error'];
}
}
//you get the following information for each file:
$_FILES['field_name']['name']
$_FILES['field_name']['size']
$_FILES['field_name']['type']
$_FILES['field_name']['tmp_name']
?>
它是從表面上工作正常教程直接複製。正如你所看到的,我曾經在頂部強制過一些錯誤報告,但是當我提交表單時,我得到的只是一個空白屏幕(瀏覽器加載file-accept.php
),上傳的文件沒有出現在uploads/
(chmoded爲777)。
編輯: 現在我正這些錯誤:
陣列([照片] =>陣列([名稱] => k3Jb9gv.jpg [型] =>圖像/ JPEG [tmp_name的值] =>/tmp/phpzc4fLT [error] => 0 [size] => 384262))
注意:未定義的索引:field_name在..............的第38,39行,40,41
您應該收到警告? – putvande
你看過你的錯誤日誌只是爲了確定嗎? –
你是否檢查過'$ message'的值是在什麼地方? – crush