slaterino Posted January 8, 2010 Share Posted January 8, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/187707-problem-with-if-isset-_filesnew_image/ Share on other sites More sharing options...
JAY6390 Posted January 8, 2010 Share Posted January 8, 2010 Not sure on your problem, but I would get rid of <?php echo $_server['php-self']; ?> immediately Since it doesn't need to be there and leaves the script open to XSS attacks Quote Link to comment https://forums.phpfreaks.com/topic/187707-problem-with-if-isset-_filesnew_image/#findComment-990957 Share on other sites More sharing options...
PFMaBiSmAd Posted January 8, 2010 Share Posted January 8, 2010 $_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 Quote Link to comment https://forums.phpfreaks.com/topic/187707-problem-with-if-isset-_filesnew_image/#findComment-990963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.