I'm trying to make a image upload in lavarel 4. The upload passes by
The file "C:\xampp\tmp\phpD1F3.tmp" does not exist
This is my upload code :
$file = Input::file('image');
// Get extension
$extension =$file->getClientOriginalExtension();
// Generate a file name
$fileName = 'pool' . Str::quickRandom();
$fileNameExtension = $fileName . '.' . $extension;
// Process upload
Input::file('image')->move(public_path() . '/uploads/images/app/pools/original/', $fileNameExtension);
`
I don't know why i get this error , please can anyone help me to solve this?
You are probably making some operations on "uploaded" file after moving it to server by move() function. Please make sure there is no operation made on temporary file after calling Input::file('image')->move() function.
Related
I am uploading images to storage/uploads and have a queue job that uploads those images to AWS. Here is the code of the job:
$path = storage_path() . '/uploads/' . $this->fileId;
$fileName = $this->fileId . '.png';
if (Storage::disk('s3images')->put('profile/' . $fileName, fopen($path, 'r+'))) {
File::delete($path);
}
Once the image has been uploaded to AWS the job is supposed to delete the image from storage/uploads but it's not doing that. The images are successfully uploaded to AWS. I tried to delete specific files directly without the if-statement but nothing seems to work. I even tried with Storage::delete but that didn't work either. Could someone point me in the right direction please?
You may use
Storage::delete('upload/profile/' . $fileName);
See Documentation
If your specifying the full directory path of the file you can use unlink a native way to delete files from the server.
$path = storage_path() . '/uploads/' . $this->fileId;
$fileName = $this->fileId . '.png';
$isUploaded = Storage::disk('s3images')->put('profile/' . $fileName, fopen($path, 'r+'));
if ($isUploaded) {
unlink($path);
}
Documentation: unlink php
I've create an app that upload image along with title, description & etc. However, i'm having a problem in some of the images to upload, it returns an error ("Image source not readable") as shown below:
Here's my Code:
$image = $request->file('image');
// $image = Input::file('image'); // already tried this one still same problem
$orginal_filename = $image->getClientOriginalName();
$ext = $image->getClientOriginalExtension();
$fileName = md5(microtime() . $orginal_filename) . '.' . $ext;
$img = Image::make($image->getRealPath());
$img->stream();
$img->resize(1200, null, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk('storage_dir')->put($dir . $fileName, $img, 'public');
Already tried following solutions:
Change to Input::file('file')
Check if Request Content-Type has multipart/form-data (Request already has multipart/form-data Content-Type)
Change Intervention Image driver from "gd" to "imagick"
but still have the "Image source not readable" error.
Note: Error only occurs in some images. (I've also tried moving the image(w/c produced the errors) into another directory but still error occurs).
Thank you so much for the help!
You can try running my code
if ($request->file('photo')->isValid()) {
$avatar = $request->file('photo');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename) );
}
/uploads/avatars/ is my directory
If the problem occours in a Laravel 5.7 project, and you store your pictures in the storage folder, it might solve the problem to enter this into the terminal:
php artisan storage:link
(The problem occurs if you have cloned the project from github og bitbucket)
Sorry for bothering guys! It seemed that it was all my fault not realizing php post_max_size and php upload_max_file_size. Since i was trying to upload an image larger than 8MB i only increased the post_max_size > than the current image file size, but not the upload_max_file_size coz i only increased it by 2 (stated: 4MB).
Thanks btw for the help and suggestions!
Replace
$resize = Image::make('storage/app/public/'.$user->image)->resize(300,300);
with
$resize = Image::make(storage_path('app/public/'.$user->image))->resize(300,300);
Give storage full path will solve the problem.
If you got this error on your server, you need to be sure you pushed the all images to server. You are facing this error because of server could not find or read to image/images.
-> Be sure image/images uploaded
-> Make readable to image/images.
I'm trying to save a .txt file in a folder named txts inside my public folder but the method i'm using is not working:
$txt_nombre = 'nomina_'. $extras['desde'] .'_'. $extras['hasta'] .'.txt';
$txt_contenido = '';
foreach ($personal as $per) {
$txt_cadena = 'BNC ' . $per->cuenta_nomina . ' ' . $per->netos . ' ' . $per->cedula_identidad;
$txt_contenido .= $txt_cadena . "\n";
}
Storage::put('public/txts/'. $txt_nombre, $txt_contenido);
It doesn't even throw an error, my function keeps running but the file is not being saved. Any idea why?
According to the Documentation
By default, the public disk uses the local driver and stores these files in storage/app/public.
Looking at your code, assuming that you haven't changed default configuration, your file should be created in storage/app/public/public/txts/ folder.
I am not sure how Laravel's Storage abstraction handles non-existing folders so you might want, for test, try using just Storage::put('file.txt', "content") and see if it's being created in storage/app/public folder
My code to upload image like this :
$file = $file->move($path, $fileName);
The code works
But I want to change it using Storage::put like this reference :
https://laravel.com/docs/5.6/filesystem#storing-files
I try like this :
Storage::put($fileName, $path);
It does not works
I'm confused, where I must put $file on the code
How can I solve this problem?
Update :
$file = file of image
$path = storage_path('/app/public/product/')
$fileName = chelsea.jpg
So I want to save the file with name chelsea.jpg on the /app/public/product/
Easy Method
$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
);
This will automatically store the files in your default configuration.
This is another example
Storage::put($fileName, $path);
Hope this helps
I am uploading an excel file from a folder in my computer to a folder in the server, after the upload i am loading the uploaded file so that i can protect certain cell, the first method i used below does not work at all
function LockCertainCells(){
$labref= $this->uri->segment(3);
$objReader = new PHPExcel_Reader_Excel2007();
$path = "analyst_uploads/" . date('Y') . '/' . date('M') . '/'. $labref .'/'. $labref . ".xlsx";
$objPHPExcel = $objReader->load($path);
$objPHPExcel->setActiveSheetIndexbyName('Sample Summary');
$objPHPExcel->getActiveSheet()->protectCells('A17:G85','PHPExcel');
$objPHPExcel ->getActiveSheet()->getProtection()->setSheet(true);
}
This second one
function LockCertainCells(){
$labref= $this->uri->segment(3);
$objPHPExcel = new PHPExcel;
$path = "analyst_uploads/" . date('Y') . '/' . date('M') . '/'. $labref .'/'. $labref . ".xlsx";
$objSheet = $objPHPExcel->load($path);
$objSheet->setActiveSheetIndexbyName('Sample Summary');
$objSheet->protectCells('A17:G85', 'PHP');
$objSheet->getProtection()->setSheet(true);
}
Throws me this error:
Fatal error: Call to undefined method PHPExcel::load() in C:\127.0.0.1\htdocs\NQCL\.....
suggestions!
The PHPExcel class doesn't have a load method, which is precisely why you get that error.... the first method is the method provided by the PHPExcel library for loading a file into a PHPExcel object, the second is not. Use the method that works (and is the method described in all the documentation); not the one that doesn't exist.
The first method for locking the cells isn't doing anything with the PHPExcel object (such as saving it) after you have set cell protection; so as soon as the LockCertainCells function terminates, it will be out of scope and discarded by the PHP script. If you want to make the changes in the file, you need to save the file again. I believe that MS Excel itself requires you to save a file if you want to make any changes to that file permanent.
EDIT
You also miss setting the password for the protected cells:
$objSheet->getProtection()->setPassword('mypassword');