Jump to content

Problem with if (isset ($_FILES['new_image']))


slaterino

Recommended Posts

Hi, I have a small problem with my script. I want to be able to add items with or without an image, and so I have part of my script that runs under this clause:

 

if (isset ($_FILES['new_image']))

 

But it doesn't seem to be working as if I try to add an item without an image it is still being run and I am therefore deluged with loads of error code. Is this the right piece of code to use for this. The part of the page that this relates to is:

<form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
</form>

Link to comment
https://forums.phpfreaks.com/topic/187707-problem-with-if-isset-_filesnew_image/
Share on other sites

$_FILES['new_image'] is an array. About the only time it won't be set is if uploads are not enabled on your server or your form is invalid.

 

$_FILES['new_image']['error'] will be a value of 4 if no file was selected to be uploaded. Your error checking logic would need to test for a value of 4 and skip over the upload processing section of your code. Your error checking logic should be testing the ['error'] element now and only processing the uploaded file if the ['error'] element has a value of 0.

 

Ref: http://us3.php.net/manual/en/features.file-upload.errors.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.