Laravel images not Writeable created with Intervention/image - php

I am working With Intervention/Image, It create some images. when i try this from saved path,
Image::make(storage_path('app/'.$photo->path));
gives,
Image source not readable.

first check to see if you have permission problems then check to see if you have done php artisan storage:link

Thank you brother! I just got it,
it is permission's problem, where Intervention/Image object was creating folder while storing file to related path.
$DesPath = "uploads/photos/u{$user->id}/{$dateFolder}/p{$ran}/";
The solution is to create those directories in the path before save file in it.
so i did this before $img->save() and it worked!.
Storage::disk('local')->makeDirectory(storage_path('app/'.$DesPath));
before
$img->save(storage_path('app/'.$DesPath).$filename);

Related

How to unlink file from children dir of parent dir? PHP

I want to unlink an image file from children dir of a parent dir.
I developing this project in a director folder under my website (mysite/project) but when i complete the project i will move to another hosting package.
Whic code i need use for stable running in all directories?
I get this error:
Warning: unlink(../../images/urunler/deneme-urun.jpg): No such file or directory in /home/admin/public_html/eticaret/admin/includes/updateproduct.php on line 120
My folder structure:
click here to see my folder structure
$delete = unlink("../../images/products/".$img);
Before running unlink() command you can check the existence of the file to get rid of such error
$path = "../../images/products/".$img;
if (file_exists(path)) {
unlink($path)
}
Better is using the full directory path (absolute path). An example, let your project structure is
and your unlinking code is in script.php, then your can get full absolute path the following way
$path = __DIR__ . "/../../images/products/{$img}";
if (file_exists(path)) {
unlink($path)
}
Thanks for all answers.
I have a fault on this topic.
Image name is xxx.jpg in my database but xxx.jpeg in the folder.
but there is an interesting situation: if you have an image as .jpeg format, you can open on browser as .jpg format.
I've tried a lot of methods to solve the above error, but I've found that.
I using chrome browser now.
So i solved my problem yet :)
as the script is run from "public_html/eticaret/admin/includes/" you need to .. traverse back 3 directories to get to public_html which is a common ancestor folder for both image and script
according to your directory image your images are in public_html/myproject/images/products/ and according to error detailed in your comment you are trying to delete from images/urunler/ I assume urunler is the actual project name.
if the folder containg your images is urunler try $delete = unlink("../../../images/urunler/".$img);
if the container folder is products try $delete = unlink("../../../images/products/".$img);
if that fails try using an absolute path instead of a relative path.

How to create a folder in a network different from root using php

Does anyone know how to create a folder in a network using php? I saw many comments and discussions about creating folder. But most of them talking about creating a folder in the root folder using mkdir().
What I need is to create a folder outside that. Lets say I want to create a folder in the ip location \\192.11.11.111\TEMP\Folder. But when I tried the following code
$structure = '\\192.11.11.111\TEMP\Folder';
mkdir ($structure);
It is producing an error Warning: mkdir(): No such file or directory in C:\MAMP\htdocs\
I also tried by using a letter instead of ip.
For Eg: z:\TEMP\Folder
But also not able to create folder. Mentioned location has full right to read and write. So issue is not due to permission also.
Can someone help?
I am able to create a folder by doing following way
$structure="//192.11.11.111/TEMP/Folder";
mkdir($structure, 0, true);
So the issue was due to the usage of wrong slashes.

Laravel Uploaded file path return error

i been following the upload method using this tutorial and i got some errors that i cant brain anymore.
Here are the example, i upload file name "fileNumber1.pdf", the laravel system will save the file using Storage facade.
$filePath[] = $fileData->storeAs('uploadedFile', $fileName);
So the original path will be "storage/app/uploadedFile/fileNumber1.pdf".
To view the file, the tutorial suggest that to use
echo asset('storage/file.txt');
So from my understanding the echo should be like
echo asset('storage/uploadedFile/fileNumber1.pdf');
Since i use local development the return is
http://localhost:8000/storage/uploadedFile/fileNumber1.pdf
Then i go to the link given, it return
Sorry, the page you are looking for could not be found.
So how is the proper way to receive or view the file?
This url http://localhost:8000/ points to pubilc folder
So store your file inside uploadedFile folder inside public folder then use like
http://localhost:8000/uploadedFile/fileNumber1.pdf
otherwise use storage_path('uploadedFile/fileNumber1.pdf'); instead asset('storage/uploadedFile/fileNumber1.pdf');
If you would have followed the tutorial link then you should have run the below command which creates a symlink, If you haven't, do run that artisan command in your application folder.
php artisan storage:link
So now the below commad will give you desired result.
{{ asset('storage/uploadedFile/fileNumber1.pdf') }}
or
{{ storage_path('uploadedFile/fileNumber1.pdf') }}
You don't have to point the complete path of your file because asset() will defaultly point you to public folder and then you have to add the required path of your file location.
sorry for all the rude if you receive.
The mistake is mine.
The solution was simple.
Original is
$filePath[] = $fileData->storeAs('uploadedFile', $fileName);
The solution is
$filePath[] = $fileData->storeAs('public/uploadedFile', $fileName);
Just add "public" before the file path before uploading.
Thanks all for the effort.

How to delete a file which is made by using file creation operations in php in a particular path?

I have created code to create file automatically in a particular path folder. I wanted to delete that file using php code. I have used the function
unlink("../game_page/$fname.php");
here the filename is stored in the variable $fname and it is a php file. But this code is not working. Can anyone say how to delete that particular file in that path?
Try this:
$_SERVER['DOCUMENT_ROOT'] after you folder path.
unlink($_SERVER['DOCUMENT_ROOT']."/game_page/".$fname.".php");
Use
unlink("../game_page/".$fname.".php");
Also check the permission if that user has to delete that file and set by using chmod

codeigniter creating a directory

How do I create a directory using codeigniter? Basically what I am trying to do is allow user to upload files and then create a directory on the fly for storing these file could anyone point me on how could I create a directory using codeigniter
Thanks
All efforts will be appreciated
I have run the following codes in windows which works perfect for me-
<?php
$path = "uploads/product";
if(!is_dir($path)) //create the folder if it's not already exists
{
mkdir($path,0755,TRUE);
}
?>
Here 0755 is permission of the folder to be created. 755 means you can do anything with the file or directory, and other users can read and execute it but not alter it. Suitable for programs and directories you want to make publicly available.
Use mkdir
mkdir("/path/to/my/dir");

Categories