【发布时间】:2014-09-18 21:52:35
【问题描述】:
我有这个 yii 应用程序,用户可以在其中上传图像,现在当我上传一个小图像(例如 17.2KB)并按提交时它工作正常。当我尝试上传 1.3MB 文件时,我收到以下错误@ 987654321@。现在我明白这是因为我按下提交它会取消上传但即使在选择一个文件然后在等待 15 分钟后按下提交它仍然给我部分上传错误。这个问题发生在我使用 yii 的每个 php 应用程序上框架或纯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,
));
}
【问题讨论】:
-
你设置
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