Unable to save the image. |
Hi,
the public/assets/img/equips/ have 777 permisions, but show a error: Unable to save the image. SYSTEMPATH/Images/Exceptions/ImageException.php at line 30 ->save(base_url().'assets/img/equips/'.$nom_arxiu, 60); if, I change ->save(base_url().'assets/img/equips/'.$nom_arxiu, 60); to ->save(WRITEPATH.'img/equips/'.$nom_arxiu, 60); save the image perfect... Any idea? public function upload() { $image = \Config\Services::image(); $file = $this->request->getFile('imatge'); if($file->isValid()) { $any=date("y"); if(strlen($any)==1){$any="0".$any;} $mes=date("m"); if(strlen($mes)==1){$mes="0".$mes;} $dia=date("d"); if(strlen($dia)==1){$dia="0".$dia;} $hor=date("H"); if(strlen($hor)==1){$hor="0".$hor;} $min=date("i"); if(strlen($min)==1){$min="0".$min;} $seg=date("s"); if(strlen($seg)==1){$seg="0".$seg;} $rand = rand(1000,9999); $path = $file->getPath(); $ext = $file->getExtension(); $nom_arxiu = 'img'."_".$rand."_".$any.$mes.$dia."_".$hor.$min.$seg.".".$ext; $image->withFile($path.'/'.$file->getFileName()) ->resize(600, 600) ->save(base_url().'assets/img/equips/'.$nom_arxiu, 60); } else { d($file->getErrorString()); } // falta update BBDD } thanks, Andreu.
Check the online manual and see if you can spot the difference between "base_url()" and "Constants".
(11-07-2019, 09:34 AM)aparedesv Wrote: Hi, this is my working code,i think this will help // create assets/avatar directory in public //Controller in add function use CodeIgniter\Files\File; // use above the class. function add() { $file = new File( $this->request->getFile( 'avatar' ) ); $ext = $file->guessExtension(); $name = 'avatar_'.$insert_id.'.'.$ext; $PATH = getcwd(); $avatar->move( $PATH .'\assets\avatar', $name ); //this will move image to folder }
thank's a lot durairaj!
a combination of each code work's! $image = \Config\Services::image(); $file = $this->request->getFile('imatge'); if($file->isValid()) { $any=date("y"); if(strlen($any)==1){$any="0".$any;} $mes=date("m"); if(strlen($mes)==1){$mes="0".$mes;} $dia=date("d"); if(strlen($dia)==1){$dia="0".$dia;} $hor=date("H"); if(strlen($hor)==1){$hor="0".$hor;} $min=date("i"); if(strlen($min)==1){$min="0".$min;} $seg=date("s"); if(strlen($seg)==1){$seg="0".$seg;} $rand = rand(1000,9999); $path = $file->getPath(); $ext = $file->getExtension(); $nom_arxiu = 'img'."_".$rand."_".$any.$mes.$dia."_".$hor.$min.$seg.".".$ext; $PATH = getcwd(); $image->withFile($path.'/'.$file->getFileName()) ->resize(600, 600) ->save($PATH .'/assets/img/equips/'. $nom_arxiu, 60); // falta update BBDD } else { d(phpinfo()); d($file->getErrorString()); } |
Welcome Guest, Not a member yet? Register Sign In |