Display various types files from server within php script
Moderator: General Moderators
Display various types files from server within php script
I was wondering how I would display various types of files within my php script. Example types of files would be .swf, .jpg, .html, .php, and so on. I need to display these types of files all on the same page, without necessarily knowing what the file extension is until I get the file path from my database. Thanks.
Re: Display various types files from server within php scrip
Some useful links:
Edit: This post was recovered from search engine cache.
- IANA: MIME Media Types
- PHP Manual: header()
Code: Select all
header('Content-Type: image/jpeg')
Last edited by McInfo on Tue Jun 15, 2010 3:44 pm, edited 1 time in total.
Re: Display various types files from server within php script
The issue is that I may need more options than jpeg for my files. Is there any better way, or generic way to do so.
Re: Display various types files from server within php scrip
That is what variables are for. Store the MIME type in the database.
You might want to use the Content-Disposition header too.
Often, file contents can be sent directly to the browser.
Edit: This post was recovered from search engine cache.
Code: Select all
header('Content-Type: '.$mime_type_from_database);Code: Select all
header('Content-Disposition: attachment');
/* or */
header('Content-Disposition: attachment; filename=generic.jpg');
/* or */
header('Content-Disposition: attachment; filename="space name.jpg"');
/* Include quotes if you use spaces in the file name. Without quotes, the file would be downloaded as "space". */
/* or */
header('Content-Disposition: attachment; filename="'.$file_name_from_database.'"');Code: Select all
echo file_get_contents($file_path_from_database);
/* or */
echo $file_contents_from_database;