只是隨着上傳文件,因爲它實際上是我以前從未做過的事情。我複製了一些here的代碼。基本文件上傳 - 500內部服務器錯誤
我從Namecheap使用cPanel託管,絕對沒有任何更改從默認配置。
我認爲最可能的問題是非常基本的,我還沒有激活。我的HTML看起來像這樣
<html>
<body>
<form action="upload_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>
</body>
</html>
和我的PHP看起來像這樣
<?php
//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']
}
當我嘗試上傳圖片,我得到一個500內部服務器錯誤,當我點擊提交。
我錯過了什麼?
感謝
你檢查了你的網絡服務器錯誤日誌?如果您啓用了錯誤日誌記錄(應該是默認情況下),它將包含錯誤信息,文件和行號,其失敗 – andersevenrud