Online Photo Gallery - Multi file uploads

Hello, i have this code to login and upload images, and to show a Photo Gallery. But i can only upload one file at a time. I need help changing this code so i can upload multiple images.
Thank you.


<?php
   error_reporting(0);
   $images_folder = "./images/";
   $columns = 4;
   $thumbnail_size = 240;
   $max_photo_size = 4194304;
   $mysql_server = '**********.se';
   $mysql_username = '*********';
   $mysql_password = '**********';
   $mysql_database = '**************';
   $mysql_table = 'PHOTO_GALLERY';
   $admin_password = isset($_COOKIE['OnlinePhotoGallery']) ? $_COOKIE['OnlinePhotoGallery'] : '';
   $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
   $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : -1;
   $timestamp = date("y-m-d H:i:s", time());

   if (empty($admin_password))
   {
      if (isset($_POST['admin_password']))
      {
         $admin_password = md5($_POST['admin_password']);
         if ($admin_password == md5('************'))
         {
            setcookie('OnlinePhotoGallery', $admin_password, time()+3600);
         }
      }
   }

   $authorized = ($admin_password == md5('patrik&1342'));
   $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
   if (!$db)
   {
      die('Failed to connect to database server!<br>'.mysql_error());
   }
   mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());

   if ($authorized)
   {
      $sql = "CREATE TABLE IF NOT EXISTS $mysql_table (id INT UNSIGNED NOT NULL AUTO_INCREMENT,
              wwb_index INT NOT NULL,
              wwb_title VARCHAR(255) NOT NULL,
              wwb_description VARCHAR(255),
              wwb_keywords VARCHAR(255),
              wwb_filename VARCHAR(50) NOT NULL,
              wwb_date TIMESTAMP NOT NULL,
              PRIMARY KEY(id));";
      $result = mysql_query($sql, $db);
      if (!$result)
      {
         die('Invalid query: ' . mysql_error());
      }
      if ($action == 'logout')
      {
         setcookie('OnlinePhotoGallery', '');
         unset($_COOKIE['OnlinePhotoGallery'], $admin_password);
         header("Location: ".basename(__FILE__));
         exit;
      }
      else
      if ($action == 'save')
      {
         $filename = "";
         if (isset($_FILES['filename']) && $_FILES['filename']['name'] != "")
         {
            if (!file_exists($images_folder))
            {
               if (!mkdir($images_folder, 0777))
               {
                  die("Failed to create images directory.");
               }
            }
            if (!file_exists($images_folder ."thumbnails/"))
            {
               if (!mkdir($images_folder ."thumbnails/", 0777))
               {
                  die("Failed to create thumbnail directory.");
               }
            }
            $error_msg = "";
            $name = $_FILES['filename']['name'];
            $type = $_FILES['filename']['type'];
            $tmp_name = $_FILES['filename']['tmp_name'];
            $error = $_FILES['filename']['error'];
            $size = $_FILES['filename']['size'];
            switch ($error)
            {
            case 0:
               if ($type == 'image/gif' || $type == 'image/jpeg' || $type == 'image/pjpeg' || $type == 'image/png' || $type == 'image/x-png')
               {
                  if ($size <= $max_photo_size)
                  {
                     if (!move_uploaded_file($tmp_name, $images_folder . $name))
                     {
                        $error_msg = "Error: Upload failed, please verify the folder's permissions.";
                     }
                     else
                     {
                        $filename = $name;
                     }
                  }
                  else
                  {
                     $error_msg = "Error: The image is too big.";
                  }
               }
               else
               {
                  $error_msg = "Error: Wrong file type, please only use jpg, gif or png images.";
               }
               break;
            case 1:
               $error_msg = "Error: The uploaded file exceeds the 'upload_max_filesize' directive.";
               break;
            case 2:
               $error_msg = "Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
               break;
            case 3:
               $error_msg = "Error: The uploaded file was only partially uploaded.";
               break;
            case 4:
               $error_msg = "Error: No file was uploaded.";
               break;
            case 6:
               $error_msg = "Error: Missing a temporary folder.";
               break;
            case 7:
               $error_msg = "Error: Failed to write file to disk.";
               break;
            case 8:
               $error_msg = "Error: File upload stopped by extension.";
               break;
            }
            if ($error_msg != "")
            {
               die($error_msg);
            }
            list($width, $height, $image_type) = getimagesize($images_folder . $name);
            $image_ratio = $width/$height;
            if ($image_ratio > 0)
            {
               $thumbnail_width = $thumbnail_size;
               $thumbnail_height = 160;
            }
            else
            {
               $thumbnail_width = $thumbnail_size;
               $thumbnail_height = 160;
            }
            $thumbnail_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
            switch ($image_type)
            {
            case IMAGETYPE_JPEG:
               $source_image = imagecreatefromjpeg($images_folder . $name);
               break;
            case IMAGETYPE_PNG:
               $source_image = imagecreatefrompng($images_folder . $name);
               break;
            default:
               $source_image = imagecreatefromgif($images_folder . $name);
               break;
            }
            imagecopyresampled($thumbnail_image, $source_image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
            $thumbnail_name = $images_folder ."thumbnails/" . "tn_" . $name;
            switch ($image_type)
            {
            case IMAGETYPE_JPEG:
               imagejpeg($thumbnail_image, $thumbnail_name, 100);
               break;
            case IMAGETYPE_PNG:
               imagepng($thumbnail_image, $thumbnail_name);
               break;
            default:
               imagegif($thumbnail_image, $thumbnail_name);
               break;
            }
         }
         $title = get_magic_quotes_gpc() ? trim($_POST['title']) : addslashes(trim($_POST['title']));
         $title = str_replace("\\\\'", "'", $title);
         $description = get_magic_quotes_gpc() ? trim($_POST['description']) : addslashes(trim($_POST['description']));
         $description = str_replace("\\\\'", "'", $description);
         $keywords = get_magic_quotes_gpc() ? trim($_POST['keywords']) : addslashes(trim($_POST['keywords']));
         $keywords = str_replace("\\\\'", "'", $keywords);
         if ($id >= 0)
         {
            $sql = "UPDATE $mysql_table SET `wwb_title` = '$title', `wwb_description` = '$description', `wwb_keywords` = '$keywords', `wwb_date` = '$timestamp'";
            if ($filename != "")
            {
               $sql .= ", `wwb_filename` = '$filename'";
            }
            $sql .= " WHERE `id` = '$id'";
            mysql_query($sql, $db);
         }
         else
         {
            $sql = "SELECT * FROM $mysql_table";
            $result = mysql_query($sql, $db);
            $wwb_index = mysql_num_rows($result);
            $wwb_index = $wwb_index + 1;
            $sql = "INSERT $mysql_table (`wwb_index`, `wwb_date`, `wwb_filename`, `wwb_title`, `wwb_description`, `wwb_keywords`) VALUES ($wwb_index, '$timestamp', '$filename', '$title', '$description', '$keywords')";
            mysql_query($sql, $db);
         }
         $id = -1;
      }
      else
      if ($action == 'delete')
      {
         $sql = "SELECT * FROM $mysql_table WHERE `id` = '$id'";
         $result = mysql_query($sql, $db);
         if ($data = mysql_fetch_array($result))
         {
            $wwb_index = $data['wwb_index'];
         }
         $sql = "DELETE FROM $mysql_table WHERE `id` = '$id'";
         mysql_query($sql, $db);
         $sql = "UPDATE $mysql_table SET wwb_index=wwb_index-1 WHERE wwb_index > '$wwb_index'";
         mysql_query($sql, $db);
         $id = -1;
      }
   }
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WWB - Online Photo Gallery</title>
<meta name="generator" content="FCAB-Web">
<link rel="stylesheet" href="./prettyPhoto/css/prettyPhoto.css">
<script src="./prettyPhoto/js/jquery.prettyPhoto.js"></script>
<script>
$(document).ready(function()
{
<?php
$lightbox = '$("a[rel^=\\'prettyPhoto_OnlinePhotoGallery\\']").prettyPhoto({theme:\\'facebook\\',social_tools:false});';
if (empty($action) && !$authorized)
{
   echo $lightbox . "\\r\
";
}
?>
});
</script>
</head>
<body>
<center><h1>RS Western Riding - Fotoalbum</h1></center>
<div id="container">
<div id="OnlinePhotoGallery" style="position:absolute;overflow:auto;left:100px;top:0px;width:1200px;height:825px;z-index:0">

<?php
   if ($action == 'admin')
   {
      echo "<form method=\\"post\\" action=\\"" .basename(__FILE__) . "\\">\
";
      echo "<input type=\\"password\\" name=\\"admin_password\\" size=\\"20\\" style=\\"height:26px;\\">\
";
      echo "<input class=\\"admin_login_button\\" type=\\"submit\\" value=\\"Logga in\\" name=\\"submit\\">\
";
      echo "</form>\
";
   }
   else
   if ($action == 'edit' || $action == 'new')
   {
      if ($authorized)
      {
         $title = '';
         $description = '';
         $keywords = '';
         if ($id >= 0)
         {
            $sql = "SELECT * FROM $mysql_table WHERE id = '".$id."'";
            $result = mysql_query($sql, $db);
            if ($data = mysql_fetch_array($result))
            {
               $title = $data['wwb_title'];
               $description = $data['wwb_description'];
               $keywords = $data['wwb_keywords'];
            }
         }
         echo "<form enctype=\\"multipart/form-data\\" action=\\"" .basename(__FILE__) . "\\" method=\\"POST\\">\
";
         echo "<table width=\\"100%\\" cellpadding=\\"0\\" cellspacing=\\"4\\" border=\\"0\\">\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Titel:</span></td><td><input type=\\"text\\" name=\\"title\\" value=\\"" .$title. "\\" size=\\"40\\"></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Beskrivning:</span></td><td><textarea name=\\"description\\" cols=\\"40\\" rows=\\"4\\">" .$description. "</textarea></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Nyckel ord:</span></td><td><input type=\\"text\\" name=\\"keywords\\" value=\\"" .$keywords. "\\" size=\\"40\\"></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Filnamn:</span></td><td><input type=\\"file\\" name=\\"filename\\" multiple=\\"multiple\\" size=\\"1\\"></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td></td><td align=\\"left\\">\
";
         echo "   <input type=\\"hidden\\" name=\\"action\\" value=\\"save\\">\
";
         echo "   <input type=\\"hidden\\" name=\\"id\\" value=\\"" . $id . "\\">\
";
         echo "   <input type=\\"submit\\" value=\\"Ladda upp\\">\
";
         echo "   <input type=\\"button\\" value=\\"Tillbaka\\" onclick=\\"window.location='" .basename(__FILE__) . "'\\">\
";
		 echo "</td>\
";
         echo "</tr>\
";
         echo "</table>\
";
         echo "</form>\
";
		
      }
   }
   else
   if ($id >= 0)
   {
      $sql = "SELECT * FROM $mysql_table WHERE id='$id'";
      $result = mysql_query($sql, $db);
      if ($data = mysql_fetch_array($result))
      {
         $image_name = $images_folder . $data['wwb_filename'];
         echo "<img alt=\\"\\" style=\\"margin:10px\\" border=\\"0\\" src=\\"$image_name\\">\\r\
";
      }
   }
   else
   {
      if ($authorized)
      {
         echo "<a class=\\"file_button\\" href=\\"".basename(__FILE__)."?action=new\\">  Välj fil/filer...  </a>  ";
         echo "<a class=\\"logout_button\\" href=\\"".basename(__FILE__)."?action=logout\\">    Logga ut    </a><br><br>\
";
      }
      $sql = "SELECT * FROM $mysql_table";
      if (isset($_GET['q']))
      {
         $terms = explode(" ", urldecode($_GET['q']));
         $sql .= " WHERE `wwb_keywords` LIKE '%";
         $sql .= $terms[0];
         $sql .= "%'";
         for ($i=1; $i<count($terms); $i++)
         {
            $sql = $sql. " AND `wwb_keywords` LIKE '%". $terms[$i] . "%'";
         }
      }
      $sql .= " ORDER BY wwb_date DESC";
      $result = mysql_query($sql, $db);
      echo "<table border=\\"0\\" cellspacing=\\"20\\" cellpadding=\\"0\\">\\r\
";
      echo "<tr>\\r\
";
      $counter = 1;
      while ($data = mysql_fetch_array($result))
      {
         $thumbnail = $images_folder . "thumbnails/tn_" . $data['wwb_filename'];
         echo "<td align=\\"center\\" valign=\\"bottom\\">\\r\
";
         echo "   <a href=\\"" . $images_folder . $data['wwb_filename'] . "\\" rel=\\"prettyPhoto_OnlinePhotoGallery[OnlinePhotoGallery]\\" title=\\"". $data['wwb_title'] . "\\">";
         echo "<img alt=\\"\\" src=\\"$thumbnail\\" border=\\"0\\"></a><br>";
         //echo "<span class='title'>" . $data['wwb_title'] . "</span><br>\\r\
";
         if ($authorized)
         {
            echo "   <table cellpadding=\\"0\\" cellspacing=\\"0\\" border=\\"0\\">\
";
            echo "   <tr>\
";
            echo "   <td>\
";
            echo "      <form action=\\"" .basename(__FILE__) . "\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"action\\" value=\\"edit\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"id\\" value=\\"" . $data['id'] . "\\">\
";
            echo "      <input type=\\"submit\\" value=\\"Ändra\\">&nbsp\
";
            echo "      </form>\
";
            echo "   </td>\
";
            echo "   <td>\
";
            echo "      <form action=\\"" .basename(__FILE__) . "\\" onSubmit=\\"return confirm('Radera - Är du säker?')\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"action\\" value=\\"delete\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"id\\" value=\\"" . $data['id'] . "\\">\
";
            echo "      <input type=\\"submit\\" value=\\"Radera\\">\
";
            echo "      </form>\
";
            echo "   </td>\
";
            echo "   </tr>\
";
            echo "   </table><br>\\r\
";
         }
         echo "</td>\\r\
";
         if ($counter != $columns)
         {
            $counter++;
         }
         else
         {
            echo "</tr>\\r\
<tr>\
";
            $counter = 1;
         }
      }
      if ($counter != 1)
      {
         while ($counter <= $columns)
         {
            echo "<td> </td>\\r\
";
            $counter++;
         }
      }
      echo "</tr>\\r\
";
      echo "</table>\\r\
";
      if (!$authorized)
      {
         echo "<a class=\\"logout_button\\" href=\\"".basename(__FILE__)."?action=admin\\">  Admin login  </a>";
      }
   }
?>
</div>
</div>
</body>
</html>

If you just want to make it so that you can upload, say, up to five images, it would just be a case of extending the input form to allow up to five images to be selected, then surround the upload code in a loop to deal with each of those form entries, checking each one to see that it is not empty first. You’d probably want to split the file upload handling off into a separate function to make it easier to read.

While you’re in there, have a look at switching from mysql to either mysqli or PDO functions for your database access, there’s an article at the top of this board with some links that will help. The older mysql libraries are being deprecated.

Thank you for your reply. But i have ni idea how to do this: then surround the upload code in a loop to deal with each of those form entries, checking each one to see that it is not empty first. I can pick multible files as it is, but they are not stored in databas and not in folder.

OK, i change some of the code now, i can pick multible files, and upload, but only one files/image is actuly uploaded(shown i gallery). Any ideas please. Thank you.

Here is the code i shanged:

$filename = "";
         if (isset($_FILES['filename']) && $_FILES['filename']['name'] != "")
         {
		 }
		 foreach($_FILES['filename']['tmp_name'] as $key => $tmp_name )
		 {
            if (!file_exists($images_folder))
            {
               if (!mkdir($images_folder, 0777)) 
               { 
                  die("Failed to create images directory.");
               }
            }
            if (!file_exists($images_folder ."thumbnails/"))
            {
               if (!mkdir($images_folder ."thumbnails/", 0777)) 
               {
                  die("Failed to create thumbnail directory.");
               }
            }
            $error_msg = "";
            $name = $key.$_FILES['filename']['name'][$key];
            $type = $_FILES['filename']['type'][$key];
            $file_tmp = $_FILES['filename']['tmp_name'][$key];
            $error = $_FILES['filename']['error'][$key];
            $size = $_FILES['filename']['size'][$key];
            switch ($error)
            {
            case 0:
               if ($type == 'image/gif' || $type == 'image/jpeg' || $type == 'image/pjpeg' || $type == 'image/png' || $type == 'image/x-png')
               {
			   
                  if ($size <= $max_photo_size)
                  {

                     if (!move_uploaded_file($file_tmp, $images_folder . $name))
                     {

and this:

echo "<td><span class=\\"label\\">Filnamn:</span></td><td><input type=\\"file\\" name=\\"filename[]\\" multiple=\\"multiple\\" size=\\"1\\"></td>\
";

Hi,
if you want to give my code (edit - should have said i have borrowed a lot of bits from other people so a bit of an mixture. Thanks to those people i have borrowed from) a try feel free. I’ve used it successfully on a live site for users to upload their photos. It uploads multiple pics but also resizes them at the same time so you get the original, a 400px wide and a 200px wide image all saved into separate folders. You can change the sizes for the resize in the code below. It saves information into a mysql table as well so you can create galleries etc and add titles and descriptions to the photos.

It’s a bit rough but it works (i’m sure it could be tidied a lot). The fiddly bit is getting the server address and folders correct. You will prob have to change the folder settings on your server to allow uploads.

hope this helps.


&lt;?php
//NEW MSQLI

$mysqli = new mysqli('localhost', 'yourdb', 'yourpassword', 'yourusername');


/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\
", mysqli_connect_error());
    exit();
}
?&gt;
&lt;?php

if(isset($_FILES['files'])){
    $errors= array();
	foreach($_FILES['files']['tmp_name'] as $key =&gt; $tmp_name ){
		$file_name = $key.$_FILES['files']['name'][$key];
		$file_size =$_FILES['files']['size'][$key];
		$file_tmp =$_FILES['files']['tmp_name'][$key];
		$file_type=$_FILES['files']['type'][$key];	
			if($file_size &gt; 2097152){
				$errors[]='File size must be less than 2 MB';
			}		
        //if new folder is specified add it to the image address
		if($_POST['folder'] !==''){$new_folder = "/".mysqli_real_escape_string($mysqli, $_POST['folder']);}
        $desired_dir="/home/sites/www.example.com/docs/images/big".$new_folder;
        if(empty($errors)==true){
            if(is_dir($desired_dir)==false){
                mkdir("$desired_dir", 0700);		// Create directory if it does not exist
            }
            if(is_dir("$desired_dir/".$file_name)==false){
                move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
            }else{									// rename the file if another one exist
                $new_dir="$desired_dir/".$file_name.time();
                 rename($file_tmp,$new_dir) ;				
            }
			
		//Lets resize the images for the thumbs
		// This is the temporary file created by PHP
		$uploadedfile = '/home/sites/www.example.com/docs/images/'.$file_name;
		
		// Create an Image from it so we can do the resize
		$src = imagecreatefromjpeg($uploadedfile);
		
		// Capture the original size of the uploaded image
		list($width,$height)=getimagesize($uploadedfile);
		
		// For our purposes, I have resized the image to be
		// 600 pixels wide, and maintain the original aspect
		// ratio. This prevents the image from being "stretched"
		// or "squashed". If you prefer some max width other than
		// 600, simply change the $newwidth variable
		$newwidth=200;
		$newheight=($height/$width)*200;
		$tmp=imagecreatetruecolor($newwidth,$newheight);
		
		// this line actually does the image resizing, copying from the original
		// image into the $tmp image
		imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
		
		// now write the resized image to disk. I have assumed that you want the
		// resized, uploaded image file to reside in the ./images subdirectory.
		$filename = "images/sml/".$file_name;
		imagejpeg($tmp,$filename,100);
		
		imagedestroy($src);
		imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
		// has completed.
		
		//Lets resize the images for the big
		// This is the temporary file created by PHP
		$uploadedfile = '/home/sites/www.example.com/docs/images/big/'.$file_name;
		
		// Create an Image from it so we can do the resize
		$src = imagecreatefromjpeg($uploadedfile);
		
		// Capture the original size of the uploaded image
		list($width,$height)=getimagesize($uploadedfile);
		
		// For our purposes, I have resized the image to be
		// 600 pixels wide, and maintain the original aspect
		// ratio. This prevents the image from being "stretched"
		// or "squashed". If you prefer some max width other than
		// 600, simply change the $newwidth variable
		$newwidth=400;
		$newheight=($height/$width)*400;
		$tmp=imagecreatetruecolor($newwidth,$newheight);
		
		// this line actually does the image resizing, copying from the original
		// image into the $tmp image
		imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
		
		// now write the resized image to disk. I have assumed that you want the
		// resized, uploaded image file to reside in the ./images subdirectory.
		$filename = "images/lrg/".$file_name;
		imagejpeg($tmp,$filename,100);
		
		imagedestroy($src);
		imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
		// has completed.
			
				$query="INSERT into upload_data (`USER_CODE`,`FILE_NAME`,`FILE_FOLDER`,`FILE_SIZE`,`FILE_TYPE`) VALUES('$user_id','$file_name','$new_folder','$file_size','$file_type') ";	
		 mysqli_query($mysqli, $query);			
        }else{
                print_r($errors);
        }
    }
	if(empty($error)){
		echo "Success";
	}
}
?&gt;


&lt;form action="" method="POST" enctype="multipart/form-data"&gt;
	&lt;input type="file" name="files[]" multiple/&gt;
    &lt;br&gt;
    Folder
    &lt;input type="text" name="folder"&gt;
    &lt;br&gt;
&lt;input type="submit"/&gt;
&lt;/form&gt;

Hi, thanks for this. I know this code works, i have tried it(or very similar code) but i need to modify the code i have. In the first post all that code is generated by a Website building tool i use, the third post (the code i changed) i got from:
http://techstream.org/Web-Development/PHP/Multiple-File-Upload-with-PHP-and-MySQL

Thank you.

Have you tried the code from the link you posted exactly as the tutorial had?

have you ensured you have ‘<form action=“” method=“POST” enctype=“multipart/form-data”>’ for your form?

Yes i have tried the code from the link i posted, and that code works. But i need to get the code in my first post to work the same. Can figuer out how to change that code so it works.

Thank you.

This is a part of my code. How would my “foreach($_FILES” look like?

$filename = "";
         if (isset($_FILES['filename']) && $_FILES['filename']['name'] != "")
         {
            if (!file_exists($images_folder))
            {
               if (!mkdir($images_folder, 0777)) 
               { 
                  die("Failed to create images directory.");
               }
            }
            if (!file_exists($images_folder ."thumbnails/"))
            {
               if (!mkdir($images_folder ."thumbnails/", 0777)) 
               {
                  die("Failed to create thumbnail directory.");
               }
            }
            $error_msg = "";
            $name = $_FILES['filename']['name'];
            $type = $_FILES['filename']['type'];
            $tmp_name = $_FILES['filename']['tmp_name'];
            $error = $_FILES['filename']['error'];
            $size = $_FILES['filename']['size'];
            switch ($error)
            {
            case 0:
               if ($type == 'image/gif' || $type == 'image/jpeg' || $type == 'image/pjpeg' || $type == 'image/png' || $type == 'image/x-png')
               {
                  if ($size <= $max_photo_size)
                  {
                     if (!move_uploaded_file($tmp_name, $images_folder . $name))
                     {