Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gif / jpeg query

Status
Not open for further replies.

ckennerdale

Programmer
Dec 23, 2000
158
GB
I am uploading graphics from my hardrive to an online folder via a form on an html page.

The file is being renamed in a temp folder with names such as "phpLMRO98 " and copied to my server. This is no problem-so far so good.

The file is not being named with an extension such as .gif or .jpg- regardless of the file I upload.

However if I try to view the graphic- referencing the new name without the extension- the graphic still displays.

Are their any known issues here. Personally I dont care- it it diaplys all well and good. But will I reun into trouble with browsers that require the extention to be thier.

If so how can I detect the file type and add the appropriate extension- would I use eregi?



Caspar Kennerdale
Senior Media Developer
 
I'm really surprised that you're able to see the graphics without an extension. The extension is what maps the file to a particular MIME type which, in turn, invokes an appropriate handler.

Anyway, regardless of what you see, it would be a good idea to keep the extensions on the file.

Try using preg_replace to do this:

$extension = preg_replace("/[\w\d\s]+(\.\w+)$/","\\1",$file['name']);

Add special characters in the first brackets as necessary. That takes the entire filename and reduces it to the extension.

brendanc@icehouse.net
 
Actually, most browsers now are able to determine the graphic type simply by the file contents, thus have no problem displaying the images. I have even tried renaming Jpegs to *.gif and vice versa, with no trouble. If you open gifs, jpegs, or pngs in a text editor, you will see that there is an identifier at the beginning.

Also, with PHP and Apache, you can force the content/type header on any particular file if you want to. PHP does this with the GD graphics library, so you can use <img src=&quot;somefile.php?args..etc...&quot;> for dynamically generated images.
 
how is it that you are able to upload graphics to the server ( I am curious because I am trying to create a Review publishing interface, that automatically stores reviews into a MySQL Database, that part I managed, but I want to be able to upload graphic files as well so that they can include images into the reviews shown ) Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top