【问题标题】:Cant upload file more then 1MB无法上传超过 1MB 的文件
【发布时间】:2014-09-18 21:52:35
【问题描述】:

我有这个 yii 应用程序,用户可以在其中上传图像,现在当我上传一个小图像(例如 17.2KB)并按提交时它工作正常。当我尝试上传 1.3MB 文件时,我收到以下错误@ 987654321@。现在我明白这是因为我按下提交它会取消上传但即使在选择一个文件然后在等待 15 分钟后按下提交它仍然给我部分上传错误。这个问题发生在我使用 yii 的每个 php 应用程序上框架或纯php。

我确实将我的 post_max_sizeupload_max_filesize 都设置为 20M。 yii 框架会发生此错误,即使是纯 php 应用程序也无法上传类似的文件。我正在运行 ubuntu 14.04。我可以使用 Apache 服务器还是我的代码构建错误?我也在我的 Windows 机器上的 WAMP 服务器上尝试过这个,但在这里页面只会一直加载,直到我关闭它。

我检查了我的两个日志错误,没有关于我在 LAMP 和 WAMP 上上传的任何内容。

我的 Yii 代码是表单上传文件的方法。

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'image-form',
    'htmlOptions'=>array('enctype'=>'multipart/form-data'),
    'enableAjaxValidation'=>false,
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model);?>

    <div class="row">
        <?php echo $form->labelEx($model,'imageUrl'); ?>
        <?php echo $form->fileField($model,'imageUrl',array('size'=>50,'maxlength'=>50)); ?>
        <?php echo $form->error($model,'imageUrl'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Upload' ,array('class'=>'button')); ?>
    </div>

<?php $this->endWidget(); ?>

我上传文件的控件如下。

public function actionCreate()
    {
        $model=new Image;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['Image']))
        {
            //Getting the values via Post
            $model->attributes=$_POST['Image'];
            //Seeting the homeId to always be Default
            $model->homeId = self::HOME_ID;
            //Generating a new name for the file
            $fileName = mt_rand();
            //Make a FILE superglobal withthe imageUrl information
            $uploadedFile=CUploadedFile::getInstance($model,'imageUrl');
            //Checking if the name is alredy taken
            $checkName = Image::model()->findAllByAttributes(array('imageUrl'=>$fileName));


            if(empty($checkName)){//If the value of the query is empty
                //Assigning the value of random number to the imageUrl
                $model->imageUrl = $fileName;
                //Assigning the value of the the extenstion to the imageExtension
                if($model->save()){
                    //Moveing the uploaded file
                    $uploadedFile->saveAs("images/upload/index/".$fileName);
                    Yii::app()->user->setFlash('success',"File  uploaded successfully");
                }
            }else{//Display error
                Yii::app()->user->setFlash('error',"Please try again");
            }

        }else{
            Yii::app()->user->setFlash('error',"Fill in all the data");
        }

        header ("Connection: close");

        $this->render('create',array(
            'model'=>$model,
        ));
    }

【问题讨论】:

  • 你设置memory_limit参数了吗?
  • 您修改了哪个 PHP 配置文件?尝试使用 echo phpinfo(); 添加一个 php 脚本来检查这些值是否真的被 PHP 使用。
  • 在您的php.ini 文件中,有几个memory_limits 关于文件上传更改这些,您应该很高兴
  • 我的内存限制是 128M @Salem 我已经配置了正确的 php.ini 文件,因为我看到了 phpinfo() 的变化;
  • @SuperDj 我的ini文件中只有一个memory_limit

标签: php apache file-upload yii ubuntu-14.04


【解决方案1】:
Did you changed the PHP.INI file like this?

upload_max_filesize = 10M
post_max_size = 8M

Remember that you need to restart Apache (if you have full access as with virtual private servers) in this (Debian) way:

/etc/init.d/apache2 restart

or be sure that Apache is restarted.

【讨论】:

  • 是的,我已经这样做了,并重新启动了 apache2 服务,当我执行 phpinfo();信息也发生了变化。
【解决方案2】:

好的,我知道了!我是因为当我将应用程序放在 LAMP 或 WAMP 服务器上时,我正在使用 phpStorm 调试我的应用程序,上传工作完美。谢谢你们的快速反应和你们给我的快速回答!欣赏!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 2012-11-02
    • 1970-01-01
    相关资源
    最近更新 更多