简体   繁体   English

获取发布文件的文件大小不起作用

[英]Get file size of posted file does not work

I am sending a file using ajax to a PHP file. 我正在使用ajax将文件发送到PHP文件。 All things go OK but the size. 一切正常,但是大小。

the jquery : jQuery的:

<script>
$('#submitshout').click(function () {
    $('.shoutinputhover').show();
    var formDatashout = new FormData($('#shoutform')[0]);
    $.ajax({
        url: "../pages/sn/ajax/submitshout.php",
        type: "POST",
        data: formDatashout,
        success: function (msg) {
            alert(msg);
            if (msg == 'update') {
                addshout();
            }
        },
        cache: false,
        contentType: false,
        processData: false
    });
   });
</script>

HTML: HTML:

    <form method="post" enctype="multipart/form-data" id="shoutform" >
    <textarea  class="ordinaryinput" style="width: 100%;height: 60px" id="shouttxtarea" name="shouttxtarea"></textarea>
    <div class="shoutaddimage">
    <input type="file" name="shoutaddimageer"  id="shoutaddimageer"  style="width: 100%"   >
    </div>
    </form>

and PHP file: 和PHP文件:

session_start();
error_reporting(E_ERROR);
header('Content-Type: text/plain; charset=utf-8'); 

require '../../../elements/config.php' ;

// get image
die($_FILES["shoutaddimageer"]["size"]);

If I place name or type instead of size in above php code it will return file type or file name accurately but it does not work with size and it returns nothing!!!! 如果我在上面的php代码中放置名称类型而不是大小,它将准确地返回文件类型或文件名,但它与大小不符,并且什么也不返回!

Since I can get file type and file name it means that sending form is going ok . 因为我可以获取文件类型和文件名,所以这意味着发送表单可以。 but whats wrong with the size ?? 但是大小怎么了?

If your file upload is aborted for any reason then have no size. 如果您的文件上传由于任何原因中止,则没有大小。
Check what will return: $_FILES['shoutaddimageer']['error'] 检查将返回什么: $_FILES['shoutaddimageer']['error']
Here is a list of errors: http://php.net/manual/en/features.file-upload.errors.php 以下是错误列表: http : //php.net/manual/zh/features.file-upload.errors.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM