【问题标题】:Uploadify sizeLimit issue上传 sizeLimit 问题
【发布时间】:2010-08-10 14:16:40
【问题描述】:

我在一个项目中使用uploadify,脚本如下:

$(document).ready(function() {

    $("#uploadify").uploadify({
        'uploader': '_assets/flash/uploadify.swf',
        'script': 'uploadify.php',
        'cancelImg': '_assets/images/nav/cancel.png',
        'folder': 'uploads',
        'queueID': 'fileQueue',
        'auto': true,
        'multi': true,
        'sizeLimit': 20971520,
        'fileExt': '*.eps;*.jpg;*.pdf;*.psd;*.mov;*.ai;*.png;*.doc;*.docx;*.ppt;*.pptx;*.indd;*.bmp;*.dwg;*.pct;*.txt;*.wmv',
        'fileDesc': 'We accept graphics and text files only!',
        'buttonImg': '_assets/images/nav/uploadbutton.png',
        'wmode': 'transparent',
        'width': 143,
        'height': 53,
        onAllComplete: function() {
            $('#forupload').hide();
            $('#confirm').fadeIn();
        }
    });

});

这个发出请求的php文件是uploadify.php:

    error_reporting(E_ALL);


if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

    // $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes  = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts  = pathinfo($_FILES['Filedata']['name']);

    // if (in_array($fileParts['extension'],$typesArray)) {
        // Uncomment the following line if you want to make the directory if it doesn't exist
        // mkdir(str_replace('//','/',$targetPath), 0755, true);

        move_uploaded_file($tempFile,$targetFile);
        echo "1";



    //Send confirmation email

    require_once('_mailClasses/class.phpmailer.php');
    include_once("_mailClasses/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail             = new PHPMailer();

    $body             = 'There is a new online order. Please check your order folder.';
    //$body             = eregi_replace("[\]",'',$body);

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "mail.splashoflondon.com";      // SMTP server
    $mail->SMTPDebug  = 2;                              // enables SMTP debug information (for testing)
    // 1 = errors and messages
    // 2 = messages only
    $mail->SMTPAuth   = true;                           // enable SMTP authentication
    $mail->Host       = "mail.splashoflondon.com";      // sets the SMTP server
    $mail->Port       = 25;                         // set the SMTP port for the GMAIL server
    $mail->Username   = "orders@splashoflondon.com";    // SMTP account username
    $mail->Password   = "blablabla";                        // SMTP account password

    $mail->SetFrom('orders@splashoflondon.com', 'Splash of London');

    $mail->AddReplyTo("sales@splashoflondon.com","Adolphus");

    $mail->Subject    = "Online Order";

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail->MsgHTML($body);

    $address = "sales@splashoflondon.com";
    $mail->AddAddress($address, "Splash Order Managment");
    $mail->Send();

    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }

}

问题在于它忽略了 20mb 的大小限制,并且不允许用户上传大于 1.something mb 的文件。

任何帮助将不胜感激。

这是我当前的 php.ini:

    register_globals = Off

post_max_size = 20M
upload_max_filesize = 20M


[Zend]

zend_optimizer.optimization_level=15

zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-2.5.10

zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-2.5.10

zend_optimizer.version=2.5.10a

zend_extension = /usr/local/lib/ioncube_loader_lin_4.4.so



zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so

zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so

【问题讨论】:

  • @XGreen:你用的是什么网络服务器?例如,apache 和 nginx 具有最大 POST 大小的配置设置。
  • 我正在使用来自加拿大提供商 HOSTPAPA 的 Apache。在 php 配置部分的域的 CPANEL 上,它说:文件上传 upload_max_filesize 上传文件的最大允许大小。 64M
  • 如何更改最大帖子大小的配置设置?我需要向项目根目录添加 .htaccess 吗?我需要编写的正确语法是什么?
  • 在 apache 中,该设置称为 LimitRequestBody。参见例如512kbps.com/2008/03/10/…
  • 我在 php.ini 中添加了最大大小和上传大小指令,但没有效果

标签: php jquery file-upload uploadify


【解决方案1】:

您可以尝试在 uploadify 调用中订阅 onError 处理程序。像这样,在 onAllComplete 处理程序之后...

onError: function (a, b, c, d) {
     if (d.status == 404)
        alert('Could not find upload script.');
     else if (d.type === "HTTP")
        alert('error '+d.type+": "+d.status);
     else if (d.type ==="File Size")
        alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
     else
        alert('error '+d.type+": "+d.text);
}

【讨论】:

  • 谢谢,虽然d.sizeLimit 没有定义
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-03
  • 2010-10-30
  • 2020-01-25
  • 2013-04-20
  • 2013-07-07
  • 1970-01-01
相关资源
最近更新 更多