i has a class that uploads images, then resizes them with the an image manipulation library(Intervention/Image)
problem is whenever i upload the image, and the resize function is called on the image, intervention/image doesn't have permissions to manipulate it. and when i check the image - it doesn't belong to me. i has no idea why it belongs to "daemon". i can chown to me with terminal but it defeats the puropse because i want it resized immediately it uploads.
i tried php chown() but i didn't expect it to work as using chown on the terminal required sudo privileges. here's the class that handles uploads. is there anything i'm doing wrong?
<?php
namespace App\Controllers\Helpers;
use App\Http\Controllers\Controller;
use Image;
class Uploads {
public $file;
public $image;
public $thumb;
public $isUploaded;
public function __construct($image){
$this->file = $image;
}
public function handle(){
$data = "";
if(is_array($this->file)){
foreach ($this->file as $file) {
if($file->isValid()){
$path = base_path().'//public/';
$name = str_replace('|', '', $file->getClientOriginalName());
$file->move($path,$name);
$data.= '|'.$path.$name;
$this->isUploaded = true;
chmod($path.$name, 0755);chown($path.$name, 'seun');
}
}
} elseif($this->file->isValid()) {
$data = '//public'.$file->getClientOriginalName();
$this->file->move(base_path().$data);
$this->isUploaded = true;
chmod(base_path().'//public/'.$file->getClientOriginalName(), 0755);chown(base_path().'//public/'.$file->getClientOriginalName(), 'seun');
} else {
$this->isUploaded = false;
}
return $data;
}
public function thumb(){
if(is_array($this->file)){
foreach ($this->file as $file) {
$image = Image::make($file)->resize(200, 150);
$image->save(base_path().'//public/thumb/'.$this->file->getClientOriginalName());
}
} else {
$image = Image::make($this->file)->resize(200, 150);
$image->save(base_path().'//public/thumb/'.$this->file->getClientOriginalName());
}
}
public function status(){
return $this->isUploaded;
}
}
Attempting chown() returns this error
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire