Multiple input field file upload in S3 using Laravel8 - amazon-s3

enter image description here
Please see the picture I have multiple input fields for file upload in AWS S3. Every input field creates its own folder and store image in S3 like Poster / Key Artwork and Poster (Quad) ... etc
Please check this code I have written.1st input field creates its own folder ( poster_art ) on s3 and stores the image but 2nd one is not working. Please help me if someone knows how to do this.
I will be very thankful to you.
public function storemultipleImages(Request $request)
{
$this->validate($request, ['image' => 'required|image']);
if ($request->hasfile('image')) {
$file = $request->file('image');
$name = time() . $file->getClientOriginalName();
$filePath = 'poster_art/' . $name;
Storage::disk('s3')->put($filePath, file_get_contents($file));
return back()->with('success', 'Image Uploaded successfully');
}
$this->validate($request, ['image' => 'image']);
if ($request->hasfile('image')) {
$file = $request->file('image');
$name = time() . $file->getClientOriginalName();
$filePath = 'poster_quad/' . $name;
Storage::disk('s3')->put($filePath, file_get_contents($file));
return back()->with('success', 'Image Uploaded successfully');
}
}

Related

Can't write image data to path in laravel 8

This is the code for my image upload.
function editProfile(Request $request){
$user = Auth::user();
if($request->file('profile_pic')){
$id = Auth::id();
$image = $request->file('profile_pic');
$filename = 'image_1'.'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('images/'. $id);
if(!File::exists($destinationPath)) File::makeDirectory($destinationPath, 775);
$img = Image::make($image->getRealPath());
$img->resize(200, 200, function ($constraint){
$constraint->aspectRatio();
})->save($destinationPath.'/'.'thumbnail.jpg');
$image->move($destinationPath, $filename);
$path = "images/" . $id. "/$filename";
$user->profile_pic = $path;
}
}
I am trying to upload image on my server( http://qa.matrimonyhouse.com/api/v1/editProfile ) and get error "Can't write image data to path (/home/cpa493ed8a5/web/public/images/1/thumbnail.jpg)", but same code work fine on local system(http://127.0.0.1:8000/api/v1/editProfile)
please help anyone.

Snappy / WKHTMLtoPDF - How to change the save folder

I'm using Laravel with the snappy wrapper. It is all working except that it saves the PDF's into the public folder. I want it to go to a different folder. There is nothing obvious on the snappy git site, nor in the config. And the wkhtlptopdf docs are very sparse imho. How do I change the $pdf->save() statement so it goes where I want it to go ?
My PDF is generated by laravel like this:
if( $email == 'email'){
$quotation = $this->quotation->get_PdfQuote($ref);
$pdf = PDF::loadView('quotations/pdf_quotation',compact('quotation') );
$pdf->save($ref.'.pdf'); //THIS SAVES INTO THE PUBLIC FOLDER.
$title = 'Your Quotation';
$firstname = $customer['firstname1'];
$pathtoFile = '/var/www/auburntree/public/'.$ref.'.pdf';
Mail::send('emails.quotation', ['title' => $title, 'firstname'=>$firstname ], function ($m) use($customer,$pathtoFile) {
$m->from('myemail#gmail.com', 'Auburntree');
$m->to($customer['email1'],($customer['firstname1'] . $customer['lastname1']))->subject('Your Quotation');
$m->attach($pathtoFile);
});
Flash::success('The Quote Has Been Saved. An Email has ben sent to the customer ');
return redirect ('quotes');
} else
Ok, I hope this helps someone else.
$quotation = $this->quotation->get_PdfQuote($ref); //pulled in from DB
$pdf = PDF::loadView('quotations/pdf_quotation',compact('quotation') );
$filename = base_path('public/pdf/'.$ref.'.pdf');
$pdf->save($filename);

Magento2 read uploaded csv file

I have upload CSV file but problem is i don't know how to read data of uploaded csv file in Magento2.
Please help me anyone.
Thanks in advance.
You can do that like you could in Magento 1. In Magento 1 you would use
new Varien_File_Csvbut in Magento 2 you can do the same with \Magento\Framework\File\Csv. You can use the following code.
In your __construct() inject the following classes:
protected $_fileCsv;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Module\Dir\Reader $moduleReader,
\Magento\Framework\File\Csv $fileCsv
) {
$this->_moduleReader = $moduleReader;
$this->_fileCsv = $fileCsv;
parent::__construct($context); // If your class doesn't have a parent, you don't need to do this, of course.
}
Then you can use it like this:
// This is the directory where you put your CSV file.
$directory = $this->_moduleReader->getModuleDir('etc', 'Vendor_Modulename');
// This is your CSV file.
$file = $directory . '/your_csv_file_name.csv';
if (file_exists($file)) {
$data = $this->_fileCsv->getData($file);
// This skips the first line of your csv file, since it will probably be a heading. Set $i = 0 to not skip the first line.
for($i=1; $i<count($data); $i++) {
var_dump($data[$i]); // $data[$i] is an array with your csv columns as values.
}
}

file name automatically change when i upload the file

I'm new to CodeIgniter and having the following issue. When I upload a file, its successfully uploaded on my local folder and the file name saved to the db. The problem is, file name has been changed after uploading.
eg:
file name "screenshot image 123.png" -> "screenshot_image_123.png"
It just convert the space into underscore;this issue occurred only when the file name having space.Other than this issue all the other files uploading successfully. Given below is my code which I used on my controller page:
public function upload_pic()
{
$image_path = realpath(APPPATH . '../uploads');
$config['upload_path'] = $image_path;
$config['allowed_types'] = "gif|jpg|jpeg|png";
$config['file_name'] = $_FILES['file']['name'];
$config['encrypt_name'] = TRUE;
$config['overwrite'] = TRUE;
$this->load->library('upload',$config);
$this->upload->initialize($config);
if(!$this->upload->do_upload('file'))
{
echo $this->upload->display_errors();
}
else
{
$finfo=$this->upload->data();
$data['uploadInfo'] = $finfo;
}
}
Can anyone help me????
Try before saving file name generate some unique
$filename = $_FILES['file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = sha1_file($filename). md5(date('Y-m-d H:i:s:u')) . '.'. $ext; //not only this you can generate any format
$config['file_name'] = $filename; //Use this file name is db too

Upload larger images using UploadedFile extension for Yii2

i want to upload images to the server and i try with success using a code that i see in a youtube video from DoingITeasyChannel.
But, it works with lightweight (150 Kb) files; i'm trying to upload a 3.1 Mb image and the program breaks.
This is my code:
public function actionCreate()
{
$model = new Images();
if ($model->load(Yii::$app->request->post())) {
$model->file = UploadedFile::getInstance($model, 'file');
$fileName = $model->category.''.date('U').'.'.$model->file->extension;
// save the path in db
$model->location = '/yii_advance/frontend'.'/web/images/'.$fileName;
$model->file->saveAs(Yii::getAlias('#frontend').'/web/images/'.$fileName);
// crea y guarda el thumbnail de la imagen subida
Image::thumbnail(Yii::getAlias('#frontend').'/web/images/'.$fileName, 220, 120)
->save(Yii::getAlias('#frontend').'/web/images/thumbs/'.$fileName, ['quality' => 80]);
$model->thumbLocation = '/yii_advance/frontend'.'/web/images/thumbs/'.$fileName;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
else {
return $this->render('create', [
'model' => $model,
]);
}
}
Can anybody help me?
NOTE:
I've tested without the thumbnail part, and i think the solution can be a way to run the "$model->save()" and the "return" after complete the upload.
Ok, like user1852788 said, the solution was in my php.ini file.
I had to change the upload_max_filesize attribute was limited for 2M.
Thanks.