lundi 30 mars 2015

issue uploading image on symfony


/**
* Upload the image while creating/updating records
* @param File Object $file
*/
public function setImageAttribute($file)
{
// Only if a file is selected
if ($file) {
File::exists(public_path() . '/uploads/') || File::makeDirectory(public_path() . '/uploads/');
File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path);
$file_name = $file->getClientOriginalName();
$image = Image::make($file->getRealPath());
if (isset($this->attributes['image'])) {
// Delete old image
$old_image = $this->getImageAttribute();
File::exists($old_image) && File::delete($old_image);
}
if (isset($this->attributes['thumb'])) {
// Delete old thumbnail
$old_thumb = $this->getThumbAttribute();
File::exists($old_thumb) && File::delete($old_thumb);
}
$image->save($this->images_path . $file_name)
->fit(640, 180)
->save($this->thumbs_path . $file_name);
$this->attributes['image'] = $file_name;
}
}


and this is my error msg



production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function getClientOriginalName() on a non-object' in C:\Doptor\app\components\posts\models\Post.php:79


line 79 is here



$file_name = $file->getClientOriginalName();
$image = Image::make($file->getRealPath());

Aucun commentaire:

Enregistrer un commentaire