fife Posted June 28, 2011 Share Posted June 28, 2011 Im trying to make sure that a user can not click upload without first choosing an image to upload. for some reason now I have put the error checking into my file uploader it has stopped working completely. It just keeps flashing the "$msg" variable. Here is the code...... if (isset($_POST['Save_photo_x'])) { $fileName1 = $_FILES['new_photo']['name']; $tmpName = $_FILES['new_photo']['tmp_name']; $fileSize = $_FILES['new_photo']['size']; $fileType = $_FILES['new_photo']['type']; $randName = md5(rand() * time()); $fileName = $randName.$fileName1; $folder = "{$_SERVER['DOCUMENT_ROOT']}members/images/{$User['county']}/"; if ($fileSize >2097152){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $success=0;} elseif (!($fileType =="image/jpg" OR $fileType=="image/gif" OR $fileType=="image/png")){$msg="You must select a file to upload and your uploaded file must be of JPG/GIF/PNG. Other file types are not allowed<BR>"; $success=0; } else {$success=1;} if ($success==1) { $var = move_uploaded_file($tmpName , $folder.$fileName); } } any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/240662-error-checking/ Share on other sites More sharing options...
mikosiko Posted June 28, 2011 Share Posted June 28, 2011 seems that you are using the negation operator incorrectly in this line: elseif (!($fileType =="image/jpg" OR $fileType=="image/gif" OR $fileType=="image/png")) test it assuming that your $fileType IS a "image/gif" per example Link to comment https://forums.phpfreaks.com/topic/240662-error-checking/#findComment-1236074 Share on other sites More sharing options...
EdwinPaul Posted June 28, 2011 Share Posted June 28, 2011 First, check wether the submit-button is clicked: if ( $_SERVER['REQUEST_METHOD'] == 'POST') { then: check wether anything is in your file-field: if((isset($_FILES['new_photo']['name'])) && (trim($_FILES['new_photo']['name']) != '')) { Link to comment https://forums.phpfreaks.com/topic/240662-error-checking/#findComment-1236075 Share on other sites More sharing options...
fife Posted June 28, 2011 Author Share Posted June 28, 2011 EdwinPaul sorry I dont understand. this is my first working image uploader. Where would I put the error result? Link to comment https://forums.phpfreaks.com/topic/240662-error-checking/#findComment-1236077 Share on other sites More sharing options...
EdwinPaul Posted June 28, 2011 Share Posted June 28, 2011 I suppose there are more fields on your form. I suppose you check each field. At least: you should. Each field may generate an error-message. Also the field where a user can (must) enter a file-name. Also this file-field should have the possibility to have an error-message shown. Without your form I can only guess... Link to comment https://forums.phpfreaks.com/topic/240662-error-checking/#findComment-1236091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.