Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.