PHP上传文件到服务器脚本不会上传所有内容

时间:2015-07-23 13:56:20

标签: php ajax file-upload

我使用php和ajax将一些文件上传到我的服务器,我可以上传txt文件,图片,文档,拉链,pdf ... 我上传了 pdf,大小为15米 b,但当我尝试上传 txt size 14mb 时,脚本崩溃了 这是我的代码

<form id="form" action="db/upload.php" method="post" enctype="multipart/formdata">
    <input type="file" name="fileToUpload" id="file">\
    <input type="submit" value="Upload Image" name="submit" id="">\
</form>

的JavaScript

//Click event for Upload new File button
$('#edit_window .file_container').on('submit', '#form', function(e) { 
    e.preventDefault();

//Code for uploading file
//get file data
      var file_data = $("#file").prop("files")[0];
      var form_data = new FormData(this);
      form_data.append('file', file_data);
      form_data.append('link', id);

      $.ajax({
        type: 'POST',
        url: 'db/upload.php',
        data:form_data,
        cache: false,
        contentType: false,
        processData: false,
        success: function (data) {
            console.log(data);
        //  $("#feedback").html(data);
        }
      });
    });

PHP

<?php
    session_start();

    //Prevent running the script if no one is logged in
    if(!isset($_SESSION["CurrentUser"]))
            exit();

    $link = $_POST['link'];
    $target_path = "../data/".$link."/";

    $target_path = $target_path . basename( $_FILES[ 'fileToUpload' ][ 'name' ] );

    if ( move_uploaded_file( $_FILES[ 'fileToUpload' ][ 'tmp_name' ] , $target_path ) ){
       echo "Upload complete!";
    } 
    else {
         echo "Error uploading!";
    }

?> 

user.ini文件

upload_max_filesize = 40M
post_max_size = 40M
max_execution_time = 10000
max_input_time = 10000

Javascript输出

<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: fileToUpload in C:\wamp\www\elmar\db\upload.php on line <i>8</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0020</td><td bgcolor='#eeeeec' align='right'>245888</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\elmar\db\upload.php' bgcolor='#eeeeec'>..\upload.php<b>:</b>0</td></tr>
</table></font>

0 个答案:

没有答案