Sami Posted September 3, 2010 Share Posted September 3, 2010 How can I make a image URL like http://example.com/file.php?name=image.jpg working?I don't actually think it's the best solution to use include() or require() and header("content-type:image/jpg") for this. Link to comment Share on other sites More sharing options...
thescientist Posted September 3, 2010 Share Posted September 3, 2010 in what context? so that it forces a download box or something? Link to comment Share on other sites More sharing options...
Synook Posted September 4, 2010 Share Posted September 4, 2010 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 More sharing options...
Sami Posted September 4, 2010 Author Share Posted September 4, 2010 Just that people who aren't logged in cannot access it.Would be nice to know how to force download box too. Link to comment Share on other sites More sharing options...
MrFish Posted September 4, 2010 Share Posted September 4, 2010 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 More sharing options...
Sami Posted September 5, 2010 Author Share Posted September 5, 2010 Yeah, but how can I store it in a database? I didn't even know that MySQL could keep files! Link to comment Share on other sites More sharing options...
thescientist Posted September 5, 2010 Share Posted September 5, 2010 you don't (have to) store the files, just the file path to the files. Link to comment Share on other sites More sharing options...
Sami Posted September 5, 2010 Author Share Posted September 5, 2010 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 More sharing options...
MrFish Posted September 5, 2010 Share Posted September 5, 2010 Yes, put it in cgi or google "how to create restricted folders". Link to comment Share on other sites More sharing options...
Sami Posted September 5, 2010 Author Share Posted September 5, 2010 I don't know CGI, and there wasn't any usefull results at Google. Link to comment Share on other sites More sharing options...
Synook Posted September 6, 2010 Share Posted September 6, 2010 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 More sharing options...
Sami Posted September 6, 2010 Author Share Posted September 6, 2010 With that code - Do I need to set the "Content-type" in the header?( header("content-type:image/jpg"); ) Link to comment Share on other sites More sharing options...
Synook Posted September 6, 2010 Share Posted September 6, 2010 Yes. There is no way around that - but don't worry, there is no performance penalty. Link to comment Share on other sites More sharing options...
Sami Posted September 9, 2010 Author Share Posted September 9, 2010 Didn't work - I couldn't see any picture. Link to comment Share on other sites More sharing options...
Synook Posted September 10, 2010 Share Posted September 10, 2010 Well, show us your code! Link to comment Share on other sites More sharing options...
Sami Posted September 10, 2010 Author Share Posted September 10, 2010 header("content-type:image/jpg");file_get_contents("a/picture.jpg");Edit: The code suggested by MrFish did work. Haven't tried it until now.. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 10, 2010 Share Posted September 10, 2010 Headers need correct capitalization and spaces, there needs to be a space after the colon in headers. Link to comment Share on other sites More sharing options...
jeffman Posted September 10, 2010 Share Posted September 10, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.