You are here: Re: Help with Image/$_FILES Handling please « PHP Programming Language « IT news, forums, messages
Re: Help with Image/$_FILES Handling please

Posted by Rik Wasmus on 11/15/07 12:41

On Thu, 15 Nov 2007 12:46:36 +0100, skulkrinbait@googlemail.com =

<skulkrinbait@googlemail.com> wrote:

> I've a HTML form that allows a user to specify the location to upload
> a file from:
>
> <p><label for =3D 'file'>Upload Graphics : <input type=3D'file'
> name=3D'imagefile' /></label></p>
>
> I then want to check if the user entered something or not as this
> isn't mandatory. Here's an excerpt of the relavent code:
>
> if (isset($_POST['submit']))
> {
> if (isset($_FILES['imagefile']))
> {
> if ($_FILES['imagefile']['type'] =3D=3D "image/gif=
")


Never ever trust a user given mime-type. Use exif_imagetype() or =

getimagesize() to check images.

> {
> copy ($_FILES['imagefile']['tmp_name'],
> "images/".$_FILES['imagefile']['name'])
> or die ("Could not copy");
>
> The problem is the line: if (isset($_FILES['imagefile'])) isn't
> doing what I expect it to do, it is always returning true and
> executing the code in the if construct.
>
> How can I solve this issue so that if the user isn't submitting
> anything to be uploaded that it doesn't execute that code and vice
> versa?

RTFM, UPLOAD_ERR_NO_FILE

if($_FILES['imagefile']['error']!=3D UPLOAD_ERR_OK){
switch($_FILES['imagefile']['error']){
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
//file was bigger then allowed
break;
case UPLOAD_ERR_PARTIAL:
//file was partially uploaded =

break;
case UPLOAD_ERR_NO_FILE:
//No file was uploaded.
break;
case UPLOAD_ERR_NO_TMP_DIR:
//Missing a temporary folder to store the upload
break;
case UPLOAD_ERR_CANT_WRITE:
//can't write upload to disk
case UPLOAD_ERR_EXTENSION:
//extention was blocked
break;
default:
//screeching halt. unkown error. abort, abort,mayday (m'aidez), alarm=
=

(a l'arme)
}
} else {
//everything fine and dandy
}

-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация