文件没有上传到PHP

时间:2015-12-22 05:03:41

标签: javascript php html

我试图将文件上传到wamp服务器,而is_upload_file对于超过10mb的文件返回false。一切都适用于较小的文件。

HTML

<button  type = "button" id = "uploadbutton">Click</button>
<form id = "fileupload">
    <input type="file" name = "uploadfile" id = "uploadfile" style="position: fixed; top: -100em; display:none">
</form>

JS

var uploadbutton = document.getElementById("uploadbutton");
var uploadFileInput = document.getElementById("uploadfile");

uploadbutton.onclick = function()
{
    uploadFileInput.click();
};

uploadFileInput.onchange = function()
{
    onSubmitFile();
};

function onSubmitFile()
{
    console.log("onsubmitform");
    var fd = new FormData(document.getElementById("fileupload"))

    $.ajax({
        url: "uploadfile.php",
        type: "POST",
        data: fd,
        enctype: 'multipart/form-data',
        processData: false,  
        contentType: false
    }).done(function( data ) {
        alert(data);
    });
}

PHP

if (is_uploaded_file($_FILES["uploadfile"]["tmp_name"]))
{
    $name = $_FILES["uploadfile"]["name"];
    move_uploaded_file($_FILES["uploadfile"]["tmp_name"], "C:\\$name");
    echo $_FILES["uploadfile"]["name"];
    echo "File uploaded";
}
else
{
    echo "File not uploaded";
}
print_r($_FILES);
print_r($_FILES)失败时,

is_uploaded_file会打印一个空数组。

php.ini

中的

upload_max_filesize 64M post_max_size 20M max_input_time 300 max_execution_time 300

5 个答案:

答案 0 :(得分:2)

请在php.ini文件中更新以下变量设置然后尝试。

set_time_limit(0);
ini_set('post_max_size', '50M');
ini_set('upload_max_filesize', '50M');

由于

答案 1 :(得分:2)

请在php.ini文件中更新以下变量设置然后尝试或在ini文件中进行更改并重新启动服务器

ini_set('post_max_size', '50M');
ini_set('upload_max_filesize', '50M');

答案 2 :(得分:2)

事实证明我正在编辑错误的php.ini。 我在Apache文件夹中编辑了ini,一切正常。

答案 3 :(得分:1)

更新以下变量设置然后尝试..

ini_set('post_max_size', '50M');
ini_set('upload_max_filesize', '50M');
ini_set('max_execution_time', 1200); // 1200 seconds i.e. 20 minutes

答案 4 :(得分:1)

您的表格应如下所示:

   <form action="formprocess.php" id='fileupload' method="post" enctype="multipart/form-data">