Jump to content

error checking


fife

Recommended Posts

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

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

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.