簡體   English   中英

基本文件上傳 - 500內部服務器錯誤

[英]Basic file upload - 500 Internal Server Error

只是玩上傳文件,因為它實際上是我以前從未做過的事情。 我從這里復制了一些所謂的工作代碼。

我正在使用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內部服務器錯誤。

我錯過了什么?

謝謝

擺脫底部的東西:

<?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'];
    }

}

不知道那是什么...另外,嘗試檢查您的CPanel中的Namecheap php.ini,看看最大上傳大小是什么,以便您的用戶得到您的錯誤,而不是PHP錯誤或500。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM