Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

SOLVED: Original Filenames in images from PHP

images php coding issues or problems here.

Moderators: macek, egami, gesf

SOLVED: Original Filenames in images from PHP

Postby Xeth » Tue Aug 26, 2003 11:10 am

Took me ages to figure this out so here it is along with keywords for search engines...

Code: Select all
# Tell the broswer that the file coming up is Jpeg/Jpg
header("Content-Type: image/jpeg");

# Tell the browser to assign the file a proper name isntead of the PHP file's name
header("Content-Disposition: inline; filename=\"$ImgName\"");

# Direct the browser to the image itself
header("location: $image_path");


Streaming PHP image files (jpg, jpeg, gif) with original filenames rather than PHP file's name. Uses content headers, disposition, location, content-type.
User avatar
Xeth
New php-forum User
New php-forum User
 
Posts: 38
Joined: Tue Jul 08, 2003 10:59 am

Postby pootergeist » Wed Aug 27, 2003 1:07 am

because you are sending a redirect ("Location: ...") header, you are still just sending the http request to the file in question. Using a location header also means you cannot access files above public root or where-ever a direct http request cannot access.
To stream the file, you'd probably do best using readfile as the last part, which does pass the content disposition to the browser properly even though the script name will still be whatever.php?ref=imagename

so

header("Content-type: image/jpeg");
header("Content-Disposition: inline; filename='New Image Name'");
readfile('image1/11.jpg');

would output the relatively linked image1/11.jpg with a src attribute of scriptname.php.
the difference would be when someone chose to save the imageby right-click-save-as - they would be given a default name of 'New Image Name'.jpg

I'm not overly certain of which parts a search engine would actually read
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby Xeth » Wed Aug 27, 2003 6:04 am

Thanks for that. Thats what I was using before, but it just took ages for the damn thing to work.

This seems to work, and right-click-save-as works too, and its pretty speedy so I have no idea whats different.

Thanks for the updated version anyhow. :D
User avatar
Xeth
New php-forum User
New php-forum User
 
Posts: 38
Joined: Tue Jul 08, 2003 10:59 am

Postby Xeth » Sat Jan 03, 2004 11:54 am

Well my British buddy, it seems the code gave up the ghost (or the pootergheist!) and I'm using yours now!

Thanks man. Happy New Year.
User avatar
Xeth
New php-forum User
New php-forum User
 
Posts: 38
Joined: Tue Jul 08, 2003 10:59 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.