I want to use the extnsions provided in yii.
Please suggest some extensions in yii to compress/decompress uploaded files. and store on the server or directory and again to decompress them while downloading..
Here I have used an extension EAjaxUpload extension for uploading the file.
IN VIEW
<?php
$this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
'id'=>'uploadResume',
'config'=>array(
'action'=>Yii::app()->baseUrl.'/index.php?r=site/word',
'allowedExtensions'=>array("doc","docx"),
'sizeLimit'=>10*1024*1024,
'minSizeLimit'=>1*1024,
'multiple'=>false,
'onComplete'=>'js:function(id, fileName, responseJSON){alert(messages);}),
?>
IN CONTROLLER
action{
Yii::import("ext.EAjaxUpload.qqFileUploader");
$folder = 'Resumes/';
$allowedExtensions = array("doc","docx");
$sizeLimit = 10 * 1024 *1024;
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder);
if(isset($result['success']))
if($result['success']==true)
{
$fileSize=filesize($folder.$result['filename']);
$fileName=$result['filename'];
$mimetype = $fileName['mime'];
}
// rename($folder.$result['filename'],$folder.$fileName);
$return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $return;
}
.
You should use your systems tools, like tar or zip/unzip, from yii you could call this commands with exec or system
Related
I installed this laravel package to convert pdf file into text. https://github.com/spatie/pdf-to-text
I'm getting this error:
Could not read sample_1610656868.pdf
I tried passing the file statically by putting it in public folder and by giving path of uploaded file.
Here's my controller:
public function pdftotext(Request $request)
{
if($request->hasFile('file'))
{
// Get the file with extension
$filenameWithExt = $request->file('file')->getClientOriginalName();
//Get the file name
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
//Get the ext
$extension = $request->file('file')->getClientOriginalExtension();
//File name to store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload File
$path = $request->file('file')->storeAS('public/ebutifier/pdf', $fileNameToStore);
}
// dd($path);
$location = public_path($path);
// $pdf = $request->input('file');
// dd($location);
// echo Pdf::getText($location, 'usr/bin/pdftotext');
$text = (new Pdf('public/ebutifier/pdf/'))
->setPdf($fileNameToStore)
->text();
return $text;
}
Not sure why it's not working any help would be appreciated.
You used spatie/pdf-to-text Package.
I also tried to use this package but it gave me this kind of error.
So, I used asika/pdf2text package and it worked properly
Asika/pdf2text pacakge
And this is my code
$path = public_path('/uploads/documents/'. $file_name);
$reader = new \Asika\Pdf2text;
$output = $reader->decode($path);
dd($output);
Hopefully, it will be helpful for you.
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);
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.
}
}
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
I have a list of image files. I need to archive those files in zip format and make the archived file downloadable. I have seen ArchiverZip class defined in the system module of Drupal 7. But I couldn't be able to create a zip file. How can I do this in Drupal 7 ? Is there any hooks or custom modules for this ? Please help me out with this.
UPDATED
Following are the codes:
$zip = new ArchiverZip('archive.zip');
foreach($_POST['img'] as $fid):
$query = db_select('file_managed', 'fn')
->condition('fid', $fid)
->fields('fn', array('filename'));
$result = $query->execute();
foreach($result as $row) {
if(file_exists('sites/default/files/'.$row->filename)){
var_dump($zip->add($base_path.'sites/default/files/'.$row->filename));
}
}
endforeach;
And this reflects the following error
Exception: Cannot open archive.zip in ArchiverZip->__construct() (line 91 of basepath\modules\system\system.archiver.inc).
Please help me with this . .
Well I missed to create the archive.zip file before creating the ArchiverZip class so the archiving operation failed previously . . Now the code will be like below:
$filename = 'archive.zip';
fopen($filename, 'w');
$zip = new ArchiverZip($filename);
foreach($_POST['img'] as $fid):
$query = db_select('file_managed', 'fn')
->condition('fid', $fid)
->fields('fn', array('filename'));
$result = $query->execute();
foreach($result as $row) {
if(file_exists('sites/default/files/'.$row->filename)){
$zip->add($base_path.'sites/default/files/'.$row->filename);
}
}
endforeach;