HTML表单文件无法上传

时间:2014-01-10 21:29:33

标签: php file-upload html-form php-ini

我有一个HTML表单如下:

<form id="addTrack" action="/worship/script/upload.php" method="post" enctype="multipart/form-data">
    <label>File:</label>
    <input type="file" name="uploaded" id="addTrackFile"/>
    <label>Key Title: </label>
    <input type="text" name="title" id="addTrackTitle"/>
    <input type="hidden" name="id" id="addTrackId"/><br>
</form>
<button onclick="uploadAddTrack()">Upload</button>
<button onclick="closeAddTrack()">Close</button>

当我提交表单时,文件会正确上传到服务器,但是当它被重定向到PHP操作脚本时,它会在第一次错误捕获时停止。然后该脚本转储它作为空数组返回的$_FILES变量。正如您在下面的代码中看到的那样,我也让它回显错误,但它也回显了一个空字符串。

为什么我没有在$_FILES数组中获取文件?

我的PHP代码:

$id=$_POST["id"];
$name=$_POST["title"];

$name = str_replace(" ","",$name);

$allowed_filetypes = array('.mp3','.m4a','.wav','.wma');

$filename = $_FILES['uploaded']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

$target = "../audio/"; 
$target = $target . $id. "_".$name.$ext; 
$ok=1; 

if ($_FILES['uploaded']['error'] !== UPLOAD_ERR_OK) {
    //------------This is where it gets stopped-----------------//

        var_dump($_FILES);
    echo $_FILES["uploaded"]["error"];
    return;
}

if(!in_array($ext,$allowed_filetypes))
die("This file type is not allowed");

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
include("updateDB.php");

header("Location:/worship/cpanel/?autoload=$id");
} 

我上传的文件大小为9mb。

我的php.ini相关信息

  

file_uploads:开启

     

upload_max_filesize:25M

     

upload_tmp_dir:没有值

     

max_post_size:8M

1 个答案:

答案 0 :(得分:2)

检查PHP.ini文件。确保POST大小超过8M。因为那是默认设置,你发送的信息是9MB。

 `; Maximum size of POST data that PHP will accept.

post_max_size = 8M`