how to print preview first before download the file while using dompdf library. - dompdf

I am using dompdf library (0.8.2) for print preview and print invoices. Below code doesnot show the print preview but download file immediately. I want to see print preview first before download the file.
I tried to array("Attachment"=>0) also, but not worked.
$dompdf = new Pdf();
$file_name = 'Invoice-'.$row["order_no"].'.pdf';
$dompdf->loadHtml($output);
//$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream($file_name,array("Attachment"=>false));
//exit(0);
}
?>

Related

How to STR Replace and echo in laravel

Files that are uploaded to my site have their names changed and extention change to bin. So for example a uploaded file will be dfd84848.bin, using the bin file worked fine with modelviewer but im trying to test babylon.js and it doesnt work with .bin only if i change .bin to .glb.
This code {{uploaded_asset($detailedProduct->cad_file)}} provides link like uploads/all/p1YZX9TBc7EmimFx4rXnSFKvVor8EttpOUUpylLL.bin
I want to change .bin to .glb and echo it.
i tried this
#php
$previewfile = uploaded_asset($detailedProduct->cad_file);
$replaced = Str::replace('.bin', '.glb', $previewfile );
#endphp
to show i used this <model url="{$replaced}"> but it never echoed url
Edit
So now that it echos as name.glb it doesnt work because the file doesnt exist on server. When 3d models such as .glb, .gltf are uploaded they are renamed to .bin i dont know why. The uploader is AizUploadController.php
To echo a value you should use double curly braces:
<model url="{{ $replaced }}">
Docs: https://laravel.com/docs/8.x/blade#displaying-data

codeigniter direct download inside application directory

I have a directory called storage inside codeigniter application directory. I want to create direct download to files in this directory. What i currently do is the below function but this isn't direct download.
function download_file($id){
$this->load->helper('download');
$data = file_get_contents(APPPATH . 'storage/videos/'.$id.'.mp4'); // Read the file's contents
force_download($id.'.mp4', $data);
}
Some of these files are gigabytes, how do i generate a direct link to these files?
See the code for creating link for direct download
<a href = "<?= base_url('storage/videos/'.$id.'.mp4') ?>" download ><?= $id.'.mp4' ?></a>

Laravel image upload creating folder instead of file

When I try to upload image from the form , Laravel is creating directory out of image name. Here is my basic code:
$file = Input::file("image");
$file = $file->move(public_path(). "/img/".$file->getClientOriginalName());
//file name is IPC_diagram.png
When die and dump I got this:
'/var/www/php/frbit/l4blog/public/img/IPC_diagram.png/phpvEb9zk'
Now name of image is name of new folder and image is renamed to some random php string, and placed in that folder.
What is the problem. Maybe something related to Linux specific handling of files. Also I was looking into symfony code for this, and symfony is trying to crete new folder every time file is moved but I don't understand how it is related to my code.
Thanks for help.
Do not use dot. Use comma, like this:
$name = time() . $file->getClientOriginalName();
$file->move('uploads/posts/',$name);

Creation of zip folder in php

I am trying to create a zip folder of my downloaded images.
Here is my code. I am not getting any errors, but the zip is not getting downloaded.The code is getting compiled and I am getting the output till the display part of the current directory, but after that the code seems to go wrong somewhere and I am not able to get any Zip archive.
<?php
$conn_id=ftp_connect("localhost") or die("Could not connect");
ftp_login($conn_id,"kishan","ubuntu"); //login to ftp localhost
echo "The current directory is " . ftp_pwd($conn_id); //display current directory
ftp_chdir($conn_id,'/var/www/test1'); //changing to the directory where my images are downloaded.
echo "<br/><p> Changing to directory" . ftp_pwd($conn_id);
$file_folder=".";
echo "<br/> The content of the directory is <br/>";
print_r(ftp_rawlist($conn_id,".")); // display the contents of the directory
if(extension_loaded('zip')) //check whether extension is loaded
{
$zip=new ZipArchive();
$zip_name="a.zip"; //some name to my zip file
if($zip->open($zip_name,ZIPARCHIVE::CREATE)!==TRUE)
{
$error="Sorry ZIP creation failed at this time";
}
$contents=ftp_nlist($conn_id,".");
foreach($contents as $file) //addition of files to zip one-by-one
{
$zip->addFile($file_folder.$file);
}
$zip->close(); //seal the zip
}
if(file_exists($zip_name)) //Content-dispostion of my zip file
{
header('Content-type:application/zip');
header('Content-Disposition:attachment; filename="'.$zip_name.'"');
readfile($zip_name);
unlink($zip_name);
}
?>
I just found that there is something wrong with the data that is passed to the for loop.
$contents=ftp_nlist($conn_id,".");
foreach($contents as $file) //addition of files to zip one-by-one
{
$zip->addFile($file_folder.$file);
}
I am not sure exactly where the thing is going wrong but here is the update. What I did was write markup using html and then passing the files to this php script via a POST method, as
foreach($post['files'] as $file){
$zip->addFile($file_folder.$file);} // Adding files into zip
This code is absolutely working fine, but now I need to figure out why post method is working and compressing my files whereas my normal for looping over files is not!!

Storing cache using .manifest file doesn't work

I'm currently developing a Web app for the iPad.
So I created the whole "application", with my different html files, my css, my pictures.
Now the next step for me is to be able to cache the files to use the "application" offline.
I follow the advices I found on different websites, with the manifest file and everything.
It seems I'm the only one with this issue, because I searched on Internet an answer to my issue, but I didn't find anything.
So I created my manifest file (ipad.manifest) which looks like this :
$CACHE MANIFEST
$/WebApp/home-start.htm
$/WebApp/accommodation.htm
$/WebApp/accommodation2.htm
$/WebApp/dining.htm
$/WebApp/entertainment.htm
$/WebApp/general.htm
$/WebApp/home.htm
$/WebApp/shopping.htm
$/WebApp/sights.htm
$/WebApp/sports.htm
$/WebApp/css/screen3.css
$/WebApp/Player/CanalVenetian.mp4
$/WebApp/Player/DancingWater.mp4
$/WebApp/Player/NaCha.mp4
$/WebApp/Player/NaCha2.mp4
$/WebApp/Player/Opening.mp4
$/WebApp/Player/previewhome.jpg
$/WebApp/Player/previewsights.jpg
$/WebApp/Player/previewvenetian.jpg
$/WebApp/Player/Venetian.mp4
$/WebApp/Player/video.js
$/WebApp/Player/Zaia.mp4
$/WebApp/iPad/startup.png
$/WebApp/iPad/pixel.gif
$/WebApp/iPad/asktt-ipad-accommodation2.jpg
$/WebApp/iPad/asktt-ipad-camera.jpg
$....
I tried with both, relative and absolute links, and it's still not working.
And in every html files I added :
$<!DOCTYPE html>
$<html manifest="ipad.manifest">
$<head>
When I go to the website with the iPad and click on "add to home screen", it adds the icon on the home screen but didn't download the content. So each time I open the application it starts to load everything....
When I tried on desktop browsers it didn't ask me to cache the content on my computer.
I added an header "content/type : text/manifest" for my mime type files on my server.
But I don't understand why it doesn't cache anything, or doesn't even ask me if I want to cache the files???
Does someone have an idea ? Or had the same issue ?
try with this, put it on the root of your app and name it manifest.php and add it to your html web app with
php file start here
$hashes="";
$dir = new RecursiveDirectoryIterator(".");
foreach(new RecursiveIteratorIterator($dir) as $file){
if ($file->IsFile() &&
$file != "./manifest.php" &&
substr($file->getFilename(),0,1) != ".")
{
echo $file . "\n";
$hashes .= md5_file($file);
}
}
echo "# Hash:" . md5($hashes) . "\n";
?>
php file ends here

Resources