duannv2081 2014-01-10 21:29
浏览 70
已采纳

HTML表单文件无法上传

I have an HTML form as the following:

<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>

When I submit the form the file uploads to the server properly, but when it gets redirected to the PHP action script, it gets stopped at the first error catch. The script then dumps the $_FILES variable which it returns as an empty array. As you can see in the code below, I also have it echo the error, but it also echoes an empty string.

Why am I not getting a file in the $_FILES array?

My PHP Code:

$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");
} 

The size of the file I am uploading is 9mb.

My php.ini relevant info

file_uploads: On

upload_max_filesize: 25M

upload_tmp_dir: no value

max_post_size: 8M

  • 写回答

1条回答 默认 最新

  • doulong2782 2014-01-10 21:45
    关注

    check you PHP.ini file. make sure the POST size is larger the 8M. because that is the default and you're sending info that is 9MB.

     `; Maximum size of POST data that PHP will accept.
    
    post_max_size = 8M`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?