For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > January 2006 > upload script question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author upload script question
Jon

2005-12-02, 8:53 pm

All,

I'm currently working on a photo upload script using PHP. Everything appears
to work fine for the most part, however it appears that some of my images do
not show up with any type... so, I'm running my script using:

if ($_FILES['imagefile']['type'] == "image/jpeg" ||
$_FILES['imagefile']['type'] == "image/pjpeg")

However, some photos have a type of nothing... so, though the file is .jpg,
the upload will fail as it's not getting the type of jpeg out of the $_FILES
array. I've tried opening the actual images that aren't working and saving
them as .jpg to make sure something didn't go bad on the original save, but
have the same problem.

Anyone seen this or know of a fix?


Jon

2005-12-05, 6:57 pm

Man, I'm stuck here - Any ideas from anyone?

"Jon" <jonra@netins.com> wrote in message
news:dmqete$55s$1@news.netins.net...
> All,
>
> I'm currently working on a photo upload script using PHP. Everything
> appears to work fine for the most part, however it appears that some of my
> images do not show up with any type... so, I'm running my script using:
>
> if ($_FILES['imagefile']['type'] == "image/jpeg" ||
> $_FILES['imagefile']['type'] == "image/pjpeg")
>
> However, some photos have a type of nothing... so, though the file is
> .jpg, the upload will fail as it's not getting the type of jpeg out of the
> $_FILES array. I've tried opening the actual images that aren't working
> and saving them as .jpg to make sure something didn't go bad on the
> original save, but have the same problem.
>
> Anyone seen this or know of a fix?
>



Steve

2005-12-05, 6:57 pm


> Man, I'm stuck here - Any ideas from anyone?


Google, as always, is Your Friend.

<http://groups.google.co.uk/group/co...9f781b04378d2da>

---
Steve

Jon

2005-12-05, 6:57 pm

I've never posted for help on a newsgroup before an exhaustive search on
google and my other normal resources.

This solution unfortunately brings me to the same problem - Is it possible
these images are just bad? If so, is there a way to "repair" them, or work
with them anyways?

"Steve" <googlespam@nastysoft.com> wrote in message
news:1133803179.878192.163940@g49g2000cwa.googlegroups.com...
>
>
> Google, as always, is Your Friend.
>
> <http://groups.google.co.uk/group/co...9f781b04378d2da>
>
> ---
> Steve
>



Philip Ronan

2005-12-05, 6:57 pm

"Jon" wrote:

> All,
>
> I'm currently working on a photo upload script using PHP. Everything appears
> to work fine for the most part, however it appears that some of my images do
> not show up with any type... so, I'm running my script using:
>
> if ($_FILES['imagefile']['type'] == "image/jpeg" ||
> $_FILES['imagefile']['type'] == "image/pjpeg")
>
> However, some photos have a type of nothing


The mime type in $_FILES[]['type'] contains data provided by the client, so
it isn't necessarily reliable, any it may not exist at all.

Instead, try using mime_content_type() to check the actual uploaded file.

http://uk.php.net/mime_content_type

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

Mr. Anonymous

2005-12-07, 3:56 am

www.0com.net

I can part with my script for $50



"Jon" <jonra@netins.com> wrote in message
news:dn23s5$b5v$1@news.netins.net...
> I've never posted for help on a newsgroup before an exhaustive search on
> google and my other normal resources.
>
> This solution unfortunately brings me to the same problem - Is it possible
> these images are just bad? If so, is there a way to "repair" them, or work
> with them anyways?
>
> "Steve" <googlespam@nastysoft.com> wrote in message
> news:1133803179.878192.163940@g49g2000cwa.googlegroups.com...
>
>



Jon

2005-12-07, 6:57 pm

For whatever reason, I can't use this function with our host. PHP 4.4.1
should be compadable, but it doesn't work. Any other possible ways?

Also - to Mr. Anonymous - Your script is only validating by file type, I was
able to save a text file as .jpg and upload it without problems. Plus,
spamming sucks :\


"Philip Ronan" <invalid@invalid.invalid> wrote in message
news:BFBA4671.3C098%invalid@invalid.invalid...
> "Jon" wrote:
>
>
> The mime type in $_FILES[]['type'] contains data provided by the client,
> so
> it isn't necessarily reliable, any it may not exist at all.
>
> Instead, try using mime_content_type() to check the actual uploaded file.
>
> http://uk.php.net/mime_content_type
>
> --
> phil [dot] ronan @ virgin [dot] net
> http://vzone.virgin.net/phil.ronan/
>



Jon

2005-12-07, 6:57 pm

Ok, I'm an idiot. The problem with my script not finding the file type was
because I set my MAX_FILE_SIZE too low, and the transfer of the file would
fail from one page to the next, therefor there was obviously no file type to
get. Live and learn - thanks for the help guys :)


"Jon" <jonra@netins.com> wrote in message
news:dn75cg$3ta$1@news.netins.net...
> For whatever reason, I can't use this function with our host. PHP 4.4.1
> should be compadable, but it doesn't work. Any other possible ways?
>
> Also - to Mr. Anonymous - Your script is only validating by file type, I
> was able to save a text file as .jpg and upload it without problems. Plus,
> spamming sucks :\
>
>
> "Philip Ronan" <invalid@invalid.invalid> wrote in message
> news:BFBA4671.3C098%invalid@invalid.invalid...
>
>



Jim Michaels

2006-01-16, 9:55 pm

someone's already done the footwork by making classes that examine the file
headers to detect the filetype.
http://phpthumb.sourceforge.net/

"Jon" <jonra@netins.com> wrote in message
news:dmqete$55s$1@news.netins.net...
> All,
>
> I'm currently working on a photo upload script using PHP. Everything
> appears to work fine for the most part, however it appears that some of my
> images do not show up with any type... so, I'm running my script using:
>
> if ($_FILES['imagefile']['type'] == "image/jpeg" ||
> $_FILES['imagefile']['type'] == "image/pjpeg")
>
> However, some photos have a type of nothing... so, though the file is
> .jpg, the upload will fail as it's not getting the type of jpeg out of the
> $_FILES array. I've tried opening the actual images that aren't working
> and saving them as .jpg to make sure something didn't go bad on the
> original save, but have the same problem.
>
> Anyone seen this or know of a fix?
>



Jim Michaels

2006-01-16, 9:55 pm

and from another post I learned about mime_content_type('php.gif')

"Jon" <jonra@netins.com> wrote in message
news:dmqete$55s$1@news.netins.net...
> All,
>
> I'm currently working on a photo upload script using PHP. Everything
> appears to work fine for the most part, however it appears that some of my
> images do not show up with any type... so, I'm running my script using:
>
> if ($_FILES['imagefile']['type'] == "image/jpeg" ||
> $_FILES['imagefile']['type'] == "image/pjpeg")
>
> However, some photos have a type of nothing... so, though the file is
> .jpg, the upload will fail as it's not getting the type of jpeg out of the
> $_FILES array. I've tried opening the actual images that aren't working
> and saving them as .jpg to make sure something didn't go bad on the
> original save, but have the same problem.
>
> Anyone seen this or know of a fix?
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com