laravel 5 cant save image - laravel-5

When trying to save an image on my server, in my laravel 5 project with intervention image class, with the following code :
$pathFull = public_path('images/original/brand/' . $filename);
$img = Image::make($image->getRealPath());
$img->encode('jpg')->save($pathFull);
I get the error:
NotWritableException in Image.php line 138:
Can't write image data to path
(/var/www/mydomain.com/public/images/original/brand/nanan.jpg)
So ive changed permission on the folder (that already exists) with:
sudo chmod -R 775 /var/www/mydomain.com/public/images
Ive checked the permissions they are 775 so that command works. I tried it localy (xampp) and it worked fine and the driectory paths are fine. I keep getting this error only if i use 777 i don't but thats danerous.
What else can I try to keep the server save and not use 777?

Maybe the paths are not the same. Check it out. See the original directory?
$pathFull = public_path('images/brand/thumb/' . $filename);
Can't write image data to path
(/var/www/mydomain.com/public/images/original/brand/nanan.jpg)
sudo chmod -R 775 /var/www/mydomain.com/public/images/original/brand
I have made recently a method like yours. It works fine for me. Here it is:
$image = Input::file('image');
$filename = Input::file('image')->getClientOriginalName();
$path = public_path('images/' . Auth::user()->email . '/' . $filename);
$img = Image::make($image->getRealPath());
$img->encode('jpg')->save($path);

Related

How can i download the files from s3 bucket to local directory using Laravel

I currently confuse why my exec command for downloading the files from s3 to local directory, not working on laravel, however in AWS command line interface, the command that I created is downloading and working well. please see the reference that I attach below.
I have here my sample code that I created on my public function
Function:
public function send_zip_files_to_store() {
$source = 's3://compexp/11-10-2019/01790exp.zip';
$destination = 'C:\xampp\htdocs';
exec('aws cp sync ' . $source . ' ' . $destination);
}
Route:
Route::get('/send_zip_files_to_store','DashController#send_zip_files_to_store')->name('send_zip_files_to_store');

codeigniter system_path and application_folder

I am running on a bitnami Linux server but I am developing on my local Win7 machine. I am having an issue with setting the system_path and application_folder on the remote Linux server in index.php. I have set
$system_path='/opt/bitnami/apache2/htdocs/sub_crud/system';
$application_folder = '/opt/bitnami/apache2/htdocs/sub_crud/application';
but a few lines down my code is getting stuck in:
// Is the system path correct?
if ( ! is_dir($system_path))
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your system folder path does not appear to be set correctly.
Please open the following file and correct this: '.pathinfo(__FILE__,
PATHINFO_BASENAME);
exit(3); // EXIT_CONFIG
}
What am I doing wrong???
Essentially it means this path "/opt/bitnami/apache2/htdocs/sub_crud/system" is not valid. You can try echoing somewhere at the start of index.php $_SERVER['DOCUMENT_ROOT'] which should give you your correct doc root.
I personally would just do
$system = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sub_crud' . DIRECTORY_SEPARATOR . 'system'

Laravel Jobs: Can't delete file after queue processed

I just cant figure why is this happening. When I dispatch job which uploads file to my Amazon S3, I want to delete id and update relation (channel). Everything works but I cant delete the file. I cant delete the file even manually. Windows says some process is still using it. To delete it manually I have to end queue worker first. Wierd part is that file is uploaded o my S3, relation is updated in database and queue worker in terminal says job is processed. No failed or running jobs in the jobs table. Anyone know whats going on?
My Job handle below.
public function handle()
{
$path = storage_path() . "/uploads/" . $this->fileId;
$fileName = $this->fileId . ".png";
if(Storage::disk("s3images")->put("profile/" . $fileName, fopen($path, "r+"))){
File::delete($path);
}
$this->channel->image_filename = $fileName;
$this->channel->save();
}
Try
unlink($path)
It worked for me.

How to download a pdf file from storage laravel

I just saw a few tutorials about Laravel storage, but I can't understand how can I create a link for the user to download the actual file that was uploaded.
I managed to upload a pdf file to:
storage/app/public/ccf/b443e9db8dc05f503ede6e670c34bf92.pdf.
I ran the artisan command: php artisan storage:link
But I can't understand what url I should put in the link for the user to download the file.
I tried:
<?php
$path1 = asset('storage/public/ccf/b443e9db8dc05f503ede6e670c34bf92.pdf');
$path2 = storage_path('ccf/b443e9db8dc05f503ede6e670c34bf92.pdf');
$path3 = Storage::url('b443e9db8dc05f503ede6e670c34bf92.pdf');
?>
Path1
Path2
Path3
None work.
This works: $path5 = Storage::url('public/ccf/b443e9db8dc05f503ede6e670c34bf92.pdf');

Laravel: create an upload directory on the fly

I have got this,
$destinationPath = public_path(). '/img/'. $username;
which I thought would create the directory alright, but it came up with a
Symfony \ Component \ HttpFoundation \ File \ Exception \ FileException
Unable to create the "/img/alvarito" directory
Any idea what is wrong? seems to me that it is trying to create also the /img/, which already exists, what I naturally want is that inside that 'img' directory creates me subdirectories for each user as they upload their files.
thanks a lot
A
You may try this:
$destinationPath = public_path(). '/img/'. $username;
if(!file_exists($destinationPath)) File::makeDirectory($destinationPath);
This will create the directory if it doesn't exist.

Resources