Error in uploading image when using cpanel - php

when developing locally, i was able to upload images in storage directory, but now as the diectory sructure changed a bit.
Now Intervention is showing an error.
Error is
message: "Image source not readable", exception: "Intervention\Image\Exception\NotReadableException",…}
exception: "Intervention\Image\Exception\NotReadableException"
This is my controller
public function submitAddProduct(Request $request){
$data = $request->validate([
'image' => ['required','image'],
'image_second' => ['required','image']
]);
//dd(request('image')->store('uploads','public'));
$imagePath = request('image')->store('uploads','public');
$image = Image::make(public_path("storage/{$imagePath}"));
$image->save();
$imagePath2 = request('image_second')->store('uploads','public');
$image2 = Image::make(public_path("storage/{$imagePath2}"));
$image2->save();
$dataVal = $request->all();
$dataVal['image'] = $imagePath;
$dataVal['image_second'] = $imagePath2;
// d3d($dataVal);
$d = Products::create($dataVal);
$id = $d->id;
if($id){
$arr = array('msg' => $id);
}
return Response()->json($arr);
}
it should get stored in the uploads directory.
My cpanel directory structure is as follows
The public_html contains
And the system folder inside the public_html contains
The symlinks are working fine, as i can see images that were previously present in uploads.
symlink.php is
<?php
symlink('/home//public_html/system/storage/app/public','/home//public_html/storage');
Only the first Image gets uploaded to storage/uploads and then interventions shows error.
Please Help

Related

laravel upload file 0 byte on the server

I use below script to uploade a file to the sevre. it works fine on the local host (wamp server), but when I try to use it on the server I figure out that the uploaded file size is 0 byte.
Any one know taht where is the problem?
public function uploadFile(Request $request)
{
$request->validate([
'name' => 'required',
'auther_id'=>'required',
'doc_type'=>'required',
'file'=>'required|mimes:pdf'
]);
$fileModel = new File;
$fileName = time().'_'.$request->file->getClientOriginalName();
$filePath = $request->file('file')->storeAs('uploads', $fileName, 'public');
$fileModel->name = time().'_'.$request->file->getClientOriginalName();
$fileModel->file_path = '/storage/' . $filePath;
$fileModel->save();
}
I think you can use like this. first of all you need to store your file inside storage. then you can get public url from storage.
Try this way
$fileName = time().'_'.$request->file->getClientOriginalName();
Storage::put('/public/uploads/'.$fileName,$request->file('file'));
$url = Storage::url('public/uploads/'.$fileName);
$fileModel = new File;
$fileModel->name = time().'_'.$request->file->getClientOriginalName();
$fileModel->file_path = $url;
$fileModel->save();
Reason of this error was permissions of some folders. I just reset the host completely and now everything work like a charm.

How Upload images with cloudinary + Laravel?

Well, what happens is that I want to upload an image to Cloudinary through Laravel,
I Follow the steps as it says on the documentation:
https://github.com/cloudinary-labs/cloudinary-laravel
and here : https://cloudinary.com/blog/laravel_file_upload_to_a_local_server_or_to_the_cloud
I am using Laravel 8, here is my code:
public function store(Request $request){
$request->validate([
'name' => 'required|string|unique:festivals|max:255', //unique:table
'description' => 'required|string|max:255',
'image' => 'required|image|dimensions:min_width=200,min_height=200',
], self::$messages);
//Here I create an instance and upload file to server
$festival = new Festival($request->all());
$path = cloudinary()->upload($request->file('image')->getRealPath())->getSecurePath();
dd($path);
//Then at field image of festivals que save the path and that goes to the database
$festival->image = 'festivals/' . basename($path);
$festival->save();
return response() -> json($festival, 201); //code 201 created
}
When I try to create a new record through Postman, this happens:
Error after register new festival
However, the image was uploaded to Cloudinary:
image uploaded
Then I tried to check if the record was created, but it was not created.
What can I do, does anyone know?
Thanks
Ok, I Solved :)
//Here I create an instance and upload file to server
$festival = new Festival($request->all());
$result = $request->image->storeOnCloudinary();
//Here I get the url
$path = $result->getPath();
//Then at field image of festivals que save the path and that goes to the database
//$festival->image = $path; output: "https://res.cloudinary.com/test/image/upload/v1226931211/zuiyb17vfs8dre6gvuov.jpg"
//$festival->image = dirname($path); output: "https://res.cloudinary.com/test/image/upload/v1526711711"
//$festival->image = basename($path); output: "zuiy31lvfs4dre5gvuov.jpg"
$base = basename(dirname($path).basename($path)); //output: "v1636941221zuiyb14vfsmdre6gvuov.jpg"
$folder = substr($base, 0, -24); //output: "v1626915261"
//So:
$img_path = $folder.'/'.basename($path);
$festival->image = 'festivals/'.$img_path; //imageFolder/imageName.jpg;
But if someone has a best way, please tell me

laravel - Uploading directory path from linux folders

I make variable that contain the path of the directory where the uploading files will be stored. I wonder this works very well on windows but not on linux ubuntu. Perhaps the way I mention directory is wrong.
Following controller on Laravel;
public function Store(Request $request){
$data = array();
$data['product_name'] = $request->product_name;
$data['product_code'] = $request->product_code;
$data['details'] = $request->details;
$image = $request->file('logo');
if($image){
$image_name = date('dmy_H_s_i');
$ext=strtolower($image->getClientOriginalExtension());
$image_full_name=$image_name.'.'.$ext;
$upload_path='home/laravel/udemy/kash';
$image_url=$upload_path.$image_full_name;
$success = $image->move($upload_path,$image_full_name);
$data['logo']=$image_url;
$product=DB::table('products')->insert($data);
return redirect()->route('product.index')
->with('success','Product Created Successfully');
}
I found solution finally. $upload_path='$home/laravel/udemy/kash/';

how can i get the working path of my image in codeigniter when uploading

I have a code in codeigniter which i will store the path of my image in my database. It works fine in inserting but the path is not correct.
My folder name of my upload images are stored in upimages.
The upimages is located in outside of application folder in codeigniter where i created assets/upimages. Here is my path code in inserting to database:
$data = $this->upload->data();
$image_path = $data['full_path'];
//var_dump($image_path);
$userid = ($this->session->userdata['logged_in']['user_id']);
$imagedb = $this->prof_model->user_img($image_path,$userid);
if(file_exists($image_path)) {
$status = "success";
$msg = "File successfully uploaded";
}
my image_path is the full path of my image but it outputs none if i call it again and here is the output of the full_path in my database:
C:/xampp/htdocs/Uploadtest/assets/upimages/test.jpg
when i change the path in my db and change it to :
http://localhost/Uploadtest/assets/upimages/test.jpg
it works fine.
my question is. how can i adjust my full_path to come up with the 2nd path. Remember that the location of my upimages is outside of the application folder which i created an asset/upimages
Try to make your file path as like as following:
$image_url = base_url().'assets/upimages/'.$data['upload_data']['file_name'];
$imagedb = $this->prof_model->user_img($image_url,$userid);

Unable to upload Image on live site

I have a site where there is member registration. All data will be saved but I get only this error:
Could not move the file "/tmp/phpa4pH3I" to "/home/sporter/public_html/someonect.org/uploads\membersImages/33921.jpg" ()
My code is like this
public function store(){
// dd(Input::all());
$validator = Validator::make(Input::all(), Members::$rules);
if($validator->passes()):
$first_name = Input::get('mem_firstName');
$last_name = Input::get('mem_lastName');
$email = Input::get('mem_email');
$image = Input::get('mem_image');
$phone = Input::get('mem_phone');
$occupation = Input::get('mem_occupation');
$citizen = Input::get('mem_citizen');
$address = Input::get('mem_address');
$destinationPathImage = str_replace('PROJECT\\', '', base_path().'\uploads\membersImages\\') ;
//Generating a random name
$randomName = rand(11111,99999);
//Renaming the image
$ImageName = $randomName.'.'.'jpg'; // renameing image
$imagePath = $destinationPathImage.$ImageName;
Members::create([
'first_name'=>$first_name,
'last_name'=>$last_name,
'email'=>$email,
'image'=>$imagePath,
'phone'=>$phone,
'occupation' => $occupation,
'citizen' => $citizen,
'address'=>$address
]);
...
I don't understrand clearly your str_replace part, but if you setup your url in config properly, you don't need this.
I'm using this kind of upload for an image:
if($request->hasFile('mem_image')) {
$file = $request->file('mem_image');
$ext = $request->file('mem_image')->getClientOriginalExtension();
$filename = rand(11111,99999). '.' . $ext;
$file->move('./uploads/', $filename);
$member->mem_image = '/uploads/' . $filename;
$member->save();
}
In case, your uploads directory is in your public folder.
If your script have permission for writing in target folder. The problem can be only in path. Check what contain in variable $destinationPathImage. It must be correct and exists path. In your error message I see problem with slashes.
also think that it's be cool to check exists of destination folder and file exists before save to database record with path of file.
You're not using the proper slashes.
Replace \uploads\membersImages\\ with /uploads/membersImages/.
If it still not working, please double check the permissions in that folder using the is_writable php function. However, have in mind that the is_writable function is not working properly on windows platforms.

Categories