Why I am getting this error ? I am uploading an image, and re-sizing it using My link image extension, But the problem, is when i upload images having greater width and height like 7000*4000 it gives me this pathetic error
( ! ) Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 28256 bytes) in G:\www\ba.dev\protected\extensions\image\drivers\Image_GD_Driver.php on line 77
. Below is my model rules.
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('image, user_id, business_id', 'required'),
array('user_id, business_id', 'numerical', 'integerOnly'=>true),
array('image', 'length', 'max'=>45),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, image, user_id, business_id', 'safe', 'on'=>'search'),
array('image', 'file','types'=>'jpg, gif, png', 'allowEmpty'=>true, 'maxSize'=>5120*3840, 'tooLarge'=>'File has to be smaller than 50MB','safe' => false,'on'=>'insert,update'),
);
}
and below is my controller.
public function actionCreate()
{
$model=new BusinessPhotos;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['BusinessPhotos']))
{
$rnd = rand(0, 9999); // generate random number between 0-9999
$model->attributes = $_POST['BusinessPhotos'];
if(isset($_POST['business_id']) /*&& isset($_POST['image'])*/)
{
$model->business_id = $_POST['business_id'];
$model->user_id = Yii::app()->user->id;
// $model->image = $_POST['image'];
}
if(isset($_POST['image']) /*&& isset($_POST['image'])*/)
{
$model->image = $_POST['image'];
echo var_dump($model->image);
}
$uploadedFile = CUploadedFile::getInstance($model, 'image');
$fileName = "{$rnd}-{$uploadedFile}"; // random number + file name
$model->image = $fileName;
if ($model->save()) {
$uploadedFile->saveAs(Yii::app()->basePath . '/../img/' . $fileName);
$image = Yii::app()->image->load(Yii::app()->basePath . '/../img/' . $fileName);
$image->resize(800, 600);
$image->save(Yii::app()->basePath . '/../img/' . $fileName);
$this->redirect('/business/addphotossuccess/'.$model->business_id);
}
}
$this->render('create', array(
'model' => $model,
));
}
Even I upload images greater than 51203840 and less than 70004000 it does not upload image instead of that the page gets refresh.What is my mistake ?