Jump to content

[Solved]File(like a picture or music) as output


Sami

Recommended Posts

If you want it to display as an image, then you need to use the right Internet media type. Why do you want such a URL, though? The main motivation for such a system is if your image data is stored in a non-web-accessible location, or apart from the filesystem, e.g. in a database. Then you can select the image data, say using a database query, and print it out. After sending the correct content-type header.

Link to comment
Share on other sites

Put it in a folder that isn't accessible by anyone. Then I think you can just call it in plain html tags using an if-statement

if($isLoggedIn)   //echo the image

Other then that, you can store it with a database or generate it manually. You can even make an image like this-

<img src="membersOnlyImage.php"/>

and membersOnlyImage.php is a generated image that sets the header to "Content-type: image/jpg". This way you can cut out the middle-man (this goes back to generating though). As for a force download-

$filename = "yourfile.txt";	header('Content-type: application/force-download');	header('Content-Disposition: attachment; filename="' . basename($filename) . '"');	header('Content-Transfer-Encoding: binary');	readfile($filename);

This will automatically start a download.

Link to comment
Share on other sites

Okay.But then, can I have the file in a path where people cannot access it?Example: The web-folder is "/var/www". Can I store the file in "/home/myUser/files/file.name", then make it accessable thrue "/var/www/file.php?get=file.name"?

Link to comment
Share on other sites

You can store entire files in a MySQL database - just use a field of type BLOB (generic binary data).

Example: The web-folder is "/var/www". Can I store the file in "/home/myUser/files/file.name", then make it accessable thrue "/var/www/file.php?get=file.name"?
Yes - just reference the file relative to the system root, e.g.:
file_get_contents("/home/myUser/files/file.name");

Link to comment
Share on other sites

Yes. There is no way around that - but don't worry, there is no performance penalty.

Link to comment
Share on other sites

We've been having a rash of case-and-space problems with headers lately.Admittedly, it is confusing to work with multiple contexts in a single environment. And the HTTP spec really could be updated. But I sense something else is afoot. (Or this may just be a recency fallacy.)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...