Jump to content

Registration Script With Photo Upload


ShoeLace1291

Recommended Posts

I have a user registration script that allows the user to upload a photo.  My problem is that I need the photo to be either a JPG, a GIF, or a PNG.  I think I have the right idea of how to do this, but I can't get my syntax to work.  This is my code for the if statement if its in the correct file format:

 

$photoname = $_FILES['photo']['name'];
   $phototype = $_FILES['photo']['type'];

   if(!($phototype == "image/jpeg") || !($phototype == "image/gif") || !($phototype == "image/png")){
   
   		echo "The photo you have chosen to upload is in an incorrect file format.  Allowed formats are jpeg, gif, and png.  You chose a $phototype.";
		$errors = $errors + 1;

}

 

And this is my code for moving the photo:

 copy( $_FILES['file']['name'], "/photos" ) or 
           die( "There was an error uploading your photo.  Please try again later.");

 

I get the error messages that I had echoed if there were an error.  This is it:

The photo you have chosen to upload is in an incorrect file format. Allowed formats are jpeg, gif, and png. You chose a .There was an error uploading your photo. Please try again later.

 

Thanks for any help.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/71093-registration-script-with-photo-upload/
Share on other sites

try this logic

if( ($phototype != "image/jpeg") && ($phototype != "image/gif") && ($phototype != "image/png") )
{

 

also it looks like the type isn't being set, can you post the form..

check the name is "photo" on the input type='file'

i don't like using image/jped or whatever else sometimes it bring problems what you can so is

$fileName = basename($_FILE['file']['name']);
$extension = strtolower(substr($fileName,-4));

switch($extension){

case '.jpg':
  echo 'good';
  break;
case '.gif':
  echo 'good';
  break;
case '.png':
  echo 'good';
  break;
default:
  echo "The photo you have chosen to upload is in an incorrect file format.  Allowed formats are jpeg, gif, and png.  You chose a $phototype.";
}

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.