I am new in laravel currently i have task which is based on PDF ..
Like :
Mearge PDF
Create PDF ,
Convert PDF etc.
But problem is this when i am search on google than there is PDF merger but i don't know how to configure PDF merger or any other Github code in laravel.
Please help. I am always appreciate.
Thanks
Link where i found some code : https://github.com/clegginabox/pdf-merger
$pdf = new \Clegginabox\PDFMerger\PDFMerger;
$pdf->addPDF('samplepdfs/one.pdf', '1, 3, 4');
$pdf->addPDF('samplepdfs/two.pdf', '1-2');
$pdf->addPDF('samplepdfs/three.pdf', 'all');
//You can optionally specify a different orientation for each PDF
$pdf->addPDF('samplepdfs/one.pdf', '1, 3, 4', 'L');
$pdf->addPDF('samplepdfs/two.pdf', '1-2', 'P);
$pdf->merge('file', 'samplepdfs/TEST2.pdf', 'P');
// REPLACE 'file' WITH 'browser', 'download', 'string', or 'file' for output options
// Last parameter is for orientation (P for protrait, L for Landscape).
// This will be used for every PDF that doesn't have an orientation specified
If I understand your question right you just need to add "clegginabox/pdf-merger": "dev-master" to your composer.json in the "require" section found in your laravel project base path. And than run composer update from your console. If you haven't configured composer read through https://getcomposer.org/ and or listen to https://laracasts.com/series/laravel-5-from-scratch its free.
i actually use this one:
https://github.com/LynX39/lara-pdf-merger/blob/master/README.md
if you need more help please let me know
Related
I install the Laravel file manager package in my app. but already I cant use thumbnail images in the blog.
How can I get an image thumbnail of uploaded photos when I use Laravel file manager?
After much searching, I realized that such a function does not exist (at least until the time of writing this message).
I defined a function in the helper that returns the address of the thumbnail from the URL of the original image.
The reader should note that these definitions may differ based on the setting of parameters for another person.
function LMFThums($url)
{
$url2= str_replace(basename($url) , '', $url ) ;
$url2=$url2.'thumbs/'.basename($url);
return $url2 ;
}
In my Laravel project I need to upload mp3 files, However Laravel using mpga as a mime type to validate mp3 files type I found that in this answer.
$results = Validator::make($request->all(), [
"song" => "required|file|mimes:mpga|max:8192",
]);
I am okay with that but my problem is the file is stored with mpga extension, I know the reason behind this weird action from this answer.
How I store the file
// Upload the song
$filePath = $request->song->store("public/songs");
But I want to store the file with mp3 extension.
Without seeing your code, the best I can suggest is to use the putFileAs() method from the Storage class.
This method allows you to specify a file name when storing your file:
use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
// Manually specify a file name:
Storage::putFileAs(
'folder',
new File('/path/to/uploaded-music.mp3'),
'stored-song-name.mp3'
);
See Laravel doc: https://laravel.com/docs/5.8/filesystem#storing-files
Edit: If you want to keep Laravel random file naming just like the putFile() method does, you can generate a random string and append your extension:
use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
// Manually specify a file name:
Storage::putFileAs(
'folder',
new File('/path/to/uploaded-music.mp3'),
Str::random(40) . '.mp3'
);
If you look at Laravel source code, this is how putFile() does it to generate a random file name.
Lobsterbaz's answer works perfectly, and i also want to give alternative to that answer which will help you to keep your file's extension as it is.
Laravel changes mp3 file's extension as mpga after uploading, so here i will show you how to keep mp3 file's extension as it is after uploading, below code will help you to do it:
use Illuminate\Support\Str;
$path = $request->file('song')->storeAs(
'songs', Str::random(40).".mp3"
);
Congrats, Now your song will be stored as mp3, but be sure to upload mp3 files only and put validation of mimes for mp3 otherwise it can break the file.
I am trying to make a joomla plugin, but I have few questions that I haven't found any answer.
What the plugin has to do: add a new field in register form(let's say Cell Number), and on form submit insert that cell number in database.
My documentation is this tutorial.
Questions:
How do you add a new field in register form? xml file is done, but I am not sure how to write the php code...(please help). What this code do?
$form->setFieldAttribute('something', 'required', $this->params->get('profile-require_something') == 2, 'profile5');
How do I get the cell number variable from that form? $jinput = JFactory::getApplication()->input; ?
Pleas help me with few tips. Thanks!
Just copy the code that is there. What will happen is that the php will automatically loop through all the fields in your xml.
$form->setFieldAttribute('something', 'required', $this->params->get('profile-require_something') == 2, 'profile5');
Is taking the field with the name something and changing it to be required if the parameter called profile-require_something is set to 2 . profile5 is the name of the xml file and the php file for the example plugin. It's the actual name of the plugin. You can have many profile plugins if you want but each needs its own name.
To get the a value you would do something like
$jinput->getString('cell_number', '');
Here is my BrandController.php
https://gist.github.com/a958926883b9e7cc68f7#file-brandcontroller-php-L53
I've gone through all my files of my custom module, and compared them to the one given from the custom module maker, and I couldn't find much differences.
Are you attempting to upload multiple files? If you're using multiple fileupload elements with the same name you'll get an array of items.
So when the following line is called,
//this way the name is saved in DB
$data['filename'] = $_FILES['filename']['name'];
It will have the value
["name"]=>array(2) {
[0]=>string(9)"file0.txt"
[1]=>string(9)"file1.txt"
}
you'll need to update the code to loop through each $_FILES['filename']['name'] and upload and save the files separately.
You may unknowingly uploaded multiple files. If you that is not your intention, you may check your in your HTML and check the name attribute of the tag. It must not be an array (like this).
<input type="file" name="my_files[]" />
If you only see Array() in your database, it means you are indeed uploading a multiple files. You can process them by using loops.
If you are really sure that you are uploading 1 image, you may follow #Palanikumar's suggestion. Use a print_r() and display the $_FILES and paste it here. IF you don't want to use that, You can use
json_encode($the-data-you-are-going-to-insert-to-the-database);
If you don't know where to put the print_r() function, you may put it after line 56 of this file.
https://gist.github.com/desbest/a958926883b9e7cc68f7#file-brandcontroller-php-L53
if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
print_r($_FILES);
die;
If saveAction() is being called inside an ajax function you need to log the ajax response. Assuming you are using jquery..
$ajaxResponse = $.POST({...});
console.log($ajaxResponse.responseText);
Then, you you can view it inside a browser's console. If nothing appears, you may use a non-async request
$ajaxResponse = $.POST({
// your options,
// your another option,
async: FALSE
});
Usually file upload will return in array format. So that each uploaded file will have the information like name, type, size, temporary name, error. You can get the file information using print function (print_r($_FILES)). So if you want to display name of the file you have to use something like this $_FILES['filename']['name']
Use print function and debugging tool then save file information using loops.
For more info please check here.
You aren't setting the enctype of the form so the image will never be sent. updated the code to
$form = new Varien_Data_Form(array( 'enctype' => 'multipart/form-data'));
How to populate image field value with drupal_execute.
for ex my content type (test) has two additional fields
1. photo (image filed),
2. phid (text field)
for phid $form_state['values']['field_phid'][0]['value'] ='14'; . how to populate photo which is image field type
If the file is already uploaded to Drupal and has a file ID (fid) then you can just do
$form_state['values']['field_image_filed'][0]['fid'] = 17; //where 17 is the Drupal file ID of the file you want input
If the file isn't already uploaded it's a lot trickier. You'll first need to programmatically create the file. I can't walk you through it off-hand but a good place to look for a template as to how it should be done is the file_service_save() function in the Services module's file_service.inc:
http://drupalcode.org/viewvc/drupal/contributions/modules/services/services/file_service/file_service.inc?revision=1.1.2.7.2.3&view=markup&pathrev=DRUPAL-6--2-2
To be clear: I'm not saying you'll use file_service_save() to accomplish the upload, but that that code shows you what needs to be done. It will show you how to save the file to the server using file_save_data(), record the file to the Drupal "files" table, then call hook_file_insert to notify other modules that a file's been saved.
i found the solution as below . i dont know pros and cons but it works fine for me.
$image = "*******/test.jpg";
$field = content_fields('field_img', 'img_test');
$validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
$files_path = filefield_widget_file_path($field);
$form_state['values']['field_img'][]= field_file_save_file($image, $validators, $files_path, FILE_EXISTS_REPLACE);