php download does not embed swf - php

I have a PHP file that sends SWF flash for client , the flash downloads but does not embed in the HTML .
Any suggestions ?
Thanks
Edit :
a normal flash file (x.swf) is embeded into the browser normally , but the downloaded one using the php file (download.php?id=1) initiates a download and does not embed and is not corrupted , i think it is a headers problem , what is the MIME type for swf ??? can't find it !

Download headers were sent or MIME type is not recognized by the browser, maybe flash player is not installed. Posting code would explain everything.

Try SWFObject, it is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file. http://code.google.com/p/swfobject/

Related

Get file contents after pageload

I have an external resource for my images let's say https://api.domain.com/api/downloads/{file_id}. The file gets downloaded after I visit that page. In this case I want to know the mimetype of the file. file_get_contents() doesn't work because the file is downloaded after I visit the page.
This means that I get HTML as output when I dump the result of file_get_contents(). I don't have any hold on how images are served to my application. So I guess I have to find a solution for this problem.
Is there a way to get the mimetype of a file after the page is loaded and it downloaded the file? If something I just wrote is not clear enough please let me know then I try to explain it further. Thanks in advance.
Some more detailed information:
I am currently creating an EML export from data from an external API from Genesys. This is pure PHP and thus I can’t make use of any client-side code like Javascript. The inline images in the body don’t show on in the EML export email body. I think this is because Genesys saves those images somewhere on their side. The image is not directly available from the URL they gave to me, because when I visit that page the page downloads a file but it is not directly served on that page.
To show the images inside the email body I want to encode them to base64 and change the src of the image to the base64 encoded image. To do so I need to know the filetype which I can’t get as described above.
Did you try with the onload property on the <img /> tag ?
<img src="w3html.gif" onload="loadImage()" width="100" height="132">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
https://www.w3schools.com/tags/ev_onload.asp
You will need to use javascript as the image is on a remote server and loaded on client side

How to download file Using PHP that has delayed force download?

I am at a situation, where I need to download files from the URL, it is easy with the direct file URLs like https://somedomain.com/some-path/somefile.exe
file_put_contents( $save_file_loc, file_get_contents($url_to_download);
But what to do when you have delayed force download from the URL which actually prints HTML and how to differentiate those URL?
Example URL: https://filehippo.com/download_mozilla-firefox-64/post_download/
EDIT: On above url the file download starts using JS, as I tested with blocking JS and download did not start.
Thanks in advance for your help.
Read the html of the URL using file_get_contents
Find the URL of the file within the HTML. You'll have to visit the page and view source to locate the URL. In your example of https://filehippo.com/download_mozilla-firefox-64/post_download/ it's found in between data-qa-download-url="https://dl5.filehippo.com/367/fb9/ef3863463463b174ae36c8bf09a90145/Firefox_Installer.exe?Expires=1594425587&Signature=18ab87cedcf3464363469231db54575665668c4f6&url=https://filehippo.com/download_mozilla-firefox-64/&Filename=Firefox_Installer.exe"
As you may have noticed, the page may have pre-approved the request so it's not guaranteed to work if the host has checks using cookies or other methods.
Create a regex based on the above to extract the URL using preg_match
Then file_get_contents the URL of the file to download it.

Open Word document in browser (Google Chrome) instead of downloading (with PHP)

Is there way to tell browser (i care mainly about Google Chrome which looks to have "Microsoft Office 2010" plugin) to open Microsoft Word document inside of browser using PHP?
RESULT: all tries made browser to download file. Looks like this Chrome plugin serves for something else than rendering .doc files.
Try setting the Content-Disposition to inline
header("Content-Disposition", "inline;filename=somefile.ext")
Yes. Set the MIME type properly and then set the Content-Disposition header to inline.
<?php
header('Content-Disposition: inline; filename=blah.doc');
?>
You could create redirect to google docs viewer with URL of the file in GET request.
For example, if you wanted to view the PDF at the URL http://research.google.com/archive/bigtable-osdi06.pdf , you would use the URL: http://docs.google.com/viewer?url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf

How to display pdf in browser

I am done with generating PDF file using FPDF in php. But the problem is how to open this pdf without the Save As option? I want to display the pdf document in the browser.
http://www.fpdf.org/en/doc/output.htm
Syntax: Output([string name] , string dest) , use I as Destination and fdpf will try to show it in the browser, if browser plugings and so on enable it
You cannot force this display, as it is up to the user to choose to display the PDF inline or systematically save them. I prefer the second option...
Now, there is a JavaScript / HTML 5 project (experimental!) to display PDF without plugin, so perhaps you can try that.
Even when using fpdf passing the output to the browser, I believe its still up to the user if they open or save it.
A solution would be to use some kind of PDF viewer, for example http://view.samurajdata.se/
Try this $pdf->Output('I', 'filename.pdf')
See the reference http://www.fpdf.org/en/doc/output.htm
Set header's content-type to 'application/pdf'. Then, most browsers will try to open it and show in-browser (or at least ask user to save or open file)
Your browser must have pdf plugin installed. If you havent done so install latest version of Acrobat Reader. If you are using fpdf, output the string instead of forcing download
For details
http://www.fpdf.org/en/doc/output.htm
Try echoing the PDF instead to using header function. The header function will force the browser to download. The echo 'might' show the pdf.

Provide file download webpage without server side code

Lets say i have this string "something1,something2" and i want to download it as "text.csv", without opening new window (pop up) how could i do this from a webpage. can i dot it in JS without using this:
window.open('data:text/csv;charset=utf-8,' + str);
or do i have to use PHP for this ?
What you want to do is a bit unconventional, but it is possible.
Take a look at Downloadify. It's a JavaScript library that leans on Flash to create a file on the client side and present the file download dialog.
David Walsh has some good demos and info too on his blog.
While limited, there is also http://en.wikipedia.org/wiki/Data_Uri
So this as a url would open an image
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
You could have javascript open this url to trigger the download
A CSV example
data:text/csv,field1%2Cfield2%0Afoo%2Cbar%0Agoo%2Cgai%0A
Just copy/paste either of those into your browser to see them work. Browser support is limited.
IE 8 for example has a 32KiB limit

Categories