不能上传文件超过1MB

时间:2014-09-18 13:18:42

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

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

我确实将 post_max_size upload_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,
        ));
    }

2 个答案:

答案 0 :(得分:0)

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.

答案 1 :(得分:0)

好的,我已经弄明白了!我是因为我使用phpStorm来调试我的应用程序,当我把它放在LAMP或WAMP服务器上时,上传工作完美。谢谢大家的快速回复和你给我的快速答案!欣赏它!