I'm trying to upload images. The uploading working perfectly, but when I'm trying to upload a jpg image it will automatically convert to jpeg. This is my code
if($request->hasFile('image'))
{
if($request->file('image')->store('public/gallery'))
{
$gallery = new Gallery();
$gallery->album_id = $request->album;
$gallery->photo = $request->image->hashName();
$gallery->save();
Session::flash('message','Success:: Image added to gallery');
Session::flash('alert','alert alert-success alert-dismissable');
return back();
}
else
{
Session::flash('message','Warning:: Failed to upload the image');
Session::flash('alert','alert alert-warning alert-dismissable');
return back()->withInput();
}
}
I'm really looking for some help, Thank you
Laravel automatically determine file's extension by examining their MIME type.
Really there are no difference between jpg and jpeg. See JPG vs. JPEG image formats
Related
I have integrated Intervention Image library (v-2.5) into my laravel application (v-5.1) to resize images. It is working fine in local server, but when i deploy it to live server i'm getting this error: Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.
. My image size is 18kb and its mime type is jpg. So there is nothing wrong with my image. Here is my code that i'm using for convertion and saving to server:
foreach ($request->images as $file) {
// getting file name with extension
$imageName = getFileName($file);
$homeworkImage = new HomeworkImage();
$homeworkImage->tbl_homework_id = $homework->homework_id;
$homeworkImage->image_name = $imageName;
if ($homeworkImage->save()) {
// $file->move('uploads/homework', $imageName);
$image_resize = Image::make($file->getRealPath());
$image_resize->resize(300, 300);
$image_resize->save('uploads/homework/' . $imageName);
}
}
If i try to upload the image normally, that it is working fine. Can anyone point me out if i'm missing something!
if anybody konws this,please help me.how to give name to pdf.
i generated pdf using mpdf codeigniter. on click of a button the pdf wil be viewed. but how can give name for that pdf? it shows 1 on the top of the pdf.how can i give name to that pdf?
My controller
public function viewpdf($key,$option) {
if($option=='1')
{
$searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata1($key);
}
if($option=='2')
{
$searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata2($key);
}
if($option=='3')
{
$searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata3($key);
}
$html=$this->load->view('moderator/pdf_data', $searchdata,true);
//this the the PDF filename that user will get to download
$pdfFilePath = "shany.pdf";
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "I");
}
Use this code.
$mpdf=new mPDF();
$mpdf->SetTitle('My Title');
$mpdf->WriteHTML('<p>Hallo World</p>');
$mpdf->Output('filename.pdf');
Set the title for the document. The title is displayed at the top of the Adobe Reader screen when viewing the PDF file
Use code as bellow
public function mypdf() {
$this->load->library('pdf');
$pdf = $this->pdf->load();
$html=$this->load->view('welcome_message',null,true);
$pdf->WriteHTML($html);
// write the HTML into the PDF
$output = 'your_given_name.pdf'; //You can give a name of your generated pdf file or you can create it auto on timestamp by using $output = time().'.pdf'.
$pdf->Output("$output", 'I');
}
If you send data to view page then replace the variable with null in line 4.
For more details please see the tutorial from here.
If you are interested on DOMPDF please see from here.
Just a doubt about camera pictures (iOS/android/windows)
//take a picture
Ti.Media.showCamera({
saveToPhotoGallery:false,
success:function(event) {
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
$.preview.image = event.media;
//insert on attachments table
database.insert('attachments',{
name:'test',
extension:'',
file:Ti.Utils.base64encode(event.media).toString()
});
}
}
});
When I send the picture to my backoffice, I need to send also the file extension, but there is no file, only the string of the encoded picture that I saved in a local SQLite table.
How do I get this extension, or it's required to save the image on the app directory?
You can set any image extension you want ! (PNG, jPEG ,..) , as you see data returned from camera is Blob ! , you don`t have to save the image local first just upload it to your server !
Hello im uploading from input form a data:image, its works well with png and jpg
but i cant get work it with GIF.
<input value="data:image/gif;base64,...................................." type="hidden" />
What i need:
Create a file from a string with out losing animation. (the other problem)
Copy to a folder
The problem
Whatever gif im trying to upload i get a error from if (!$image) that image is not valid. Why ?
If i remove $image = #imagecreatefromgif($image); All works but image copied is only first frame from the gif, so its not animated (i heard GD have problems with it, maybe i can just copy full image from datestring, but how to save it right ? )
Im tried to use Gifencoder and Gifdecoder and imagemagick but the problem its doesn't recognize a image from datastring , i need to blob it ?
Here is my code
function ImageUploadString($data_string)
{
$data_string = str_replace('data:image/gif;base64,', '', $data_string);
$data_string = base64_decode($data_string); // decode image from base64
$image = imagecreatefromstring($data_string);
if ($image !== false) {
$random_imagename = str_shuffle(MD5(microtime()));
$extention = "gif";
$ufname = 'folder/'.$random_imagename.'.'.$extention;
$image = #imagecreatefromgif($image); /* Attempt to open */
if (!$image) {
imagedestroy($image);
die('gif error');
}
imagegif($image, $ufname);
}
}
$imagebase = "data:image/gif;base64,..........................................";
ImageUploadString($imagebase);
when i upload file in mvc3 project i need validation for sicze limit and user only upload image, doc and xls file. should be there like required field, wrong selection of file, size limitation in asp.net mvc3
Personally, I use the Telerik uploader control and I set this as the method that runs when the file is selected but it can be used with a standard file uploader as well
function onSelect(e) {
if (e.files[0].size > 256000) {
alert('The file size is too large for upload');
e.preventDefault();
return false;
}
// Array with information about the uploaded files
var files = e.files;
var ext = $('#logo').val().split('.').pop().toLowerCase();
if ($.inArray(ext, ['gif', 'jpeg', 'jpg', 'png', 'tif', 'pdf']) == -1) {
alert('This type of file is restricted from being uploaded due to security reasons');
e.preventDefault();
return false;
}
return true;
}
Basically, it says if the file is over 256k it's too big and will only allow gif, jpeg, jpg, png, tif and pdf files...