簡體   English   中英

無法上傳超過1MB的文件

[英]Cant upload file more then 1MB

我有這個yii應用程序,用戶可以在其中上傳圖像,現在當我上傳小的圖像(例如17.2KB)並按Submit時,它可以正常工作。當我嘗試上傳1.3MB的文件時,出現以下錯誤鏈接 現在我知道發生這種情況的原因是我按Submit取消了上傳,但是即使選擇了一個文件,然后等待15分鍾后按Submit仍然給了我部分上傳錯誤。這個問題在我使用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,
        ));
    }
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.

好的,我知道了! 我當時是因為我將phpStorm放在LAMP或WAMP服務器上時正在使用phpStorm調試應用程序,因此上載效果很好。 謝謝你們給我的快速答復和快速答復! 謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM