Asked  7 Months ago    Answers:  5   Viewed   24 times

I am trying to make an online kickstart config file creator. After the file is created on the server how do I get the download dialog to pop up so the user can download it?

 Answers

42

Content-Disposition header..

// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');

http://au2.php.net/manual/en/function.header.php

Wednesday, March 31, 2021
 
Blur
answered 7 Months ago
27

I found the error:

 $name_file="test2.apk";
 $path="/home/user/public_html/apk/"; 
 $dimension_file=(string)filesize($name_file); //<-- HERE! --- 

i was retrieving the size using only the name of file instead of using the full path

filesize($name_file) ---> filesize( $path . $name_file) 

the error was hidden from

header("Content-Type: application/vnd.android.package-archive"); 

and the php error response added to the content of the downloaded file.

So i suggest to who has this kind of problems to comment the "Content-Type" while debugging to see if there are some errors in the php code and when all code seems to work re-enable the "Content-Type" header.

On my server spaces in the code before the

readfile($path.$name_file);

has no influence on the checksum

Thanks to Vladimir and Rocket for good practice tips

Wednesday, March 31, 2021
 
liquidmotion
answered 7 Months ago
37

add target=_blank in your ajax success function like below

success: function(){
  window.open('http://YOUR_URL','_blank' );
},

otherwise you can handle smartly to open your Excel download link in new tab with jQuery trigger function or etc.

Monday, July 19, 2021
 
Jubair
answered 3 Months ago
13

The first thing you should do is get a tool like Fiddler and visit a YouTube video page. In Fiddler, you will see all of the files that make up that page, including the FLV itself. Now, you know that the video isn't one of the CSS files, nor is it the image files. You can ignore those. Look for a big file. If you look at the URL, it begins with /videoplayback.

Now, once you've found it, figure out how the browser knew to get that file. Do a search through the sessions (Ctrl+F) and look for "videoplayback". You will see a hit on the first page you went to, like http://www.youtube.com/watch?v=123asdf. If you dig through that file, you'll see a DIV tag with the ID of "watch-player". Within that there is a script tag to setup the flash player, and within that are all of the flash parameters. Within those is the URL to the video.

So now you know how to use your tools to figure out how the browser got to it. How do you duplicate this behavior in PHP?

Do a file_get_contents() on the page that references the video. Ignore everything not in that watch-player div. Parse through the code until you find that variable that contains the URL. From there you will probably have to unescape that URL. Once you have it, you can do a file_get_contents() (or some other download method, depending on what you are trying to do) to get the URL. it is that simple. Your HTML parsing code will be the most complex.

Finally, keep in mind what you are about to do may be illegal. Check the EULA.

Sunday, August 8, 2021
 
im1dermike
answered 2 Months ago
83

just use the builtin functionality as follows

$phpWord->save('teste.docx', 'Word2007', true);

The last parameter will force a download of the produced file.

Thursday, September 2, 2021
 
Manse
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :