View file script/admin/add_photo.php

File size: 5.27Kb
<?php
/*-----------------------------------------------------------------------------------------
mcGalleryPRO
All code is © 2003 Marc Cagninacci.
No files may be redistributed in whole or significant part.
----------------- mcgalleryPRO IS NOT FREE SOFTWARE -------------------
You should have receive a file called license.txt in this package
--------------------------------------------------------------------------------------------*/

session_start();
if (empty($_SESSION['private_login']))
{
include "./sess.php";
exit;
}


if (!empty($_FILES))
{
$uploadedfile = $_FILES['uploadedfile']['name'];
$uploaded = $_FILES['uploadedfile']['tmp_name'];
$uploadedfile_type = $_FILES['uploadedfile']['type'];
}

if (!isset($func))
{
$func = "one";
}

switch ($func) {
case one:
$dir = '../photos/'.$idalbum;
echo '<form method="post" enctype="multipart/form-data" action="detailphoto.php">';
echo '<table border="0" align="center" cellspacing="1" cellpadding="3" bgcolor="#000000">';
echo '<tr><td bgcolor="#DDDDDD" align="center" colspan="5"><font face="verdana" size="2" color="black">';
echo $l_Addphoto.' <b>'.stripslashes($nom_album[0]).'</b></font></td>';
echo '<td bgcolor="#000000" align="left"><input type="file" name="uploadedfile" size="30" maxlenght="90">';
echo '</td>';
echo ' <input type="hidden" name="idalbum" value="'.$idalbum.'">';
echo ' <input type="hidden" name="album" value="'.stripslashes($nom_album[0]).'">';
echo '<input type="hidden" name="func" value="two">';
echo '<td bgcolor="#000000"><input type="submit" name="submitfile" value="OK"></td></tr>';
echo '</table></form>';

break;

case two:

echo '<table align="center"><tr><td class="td2" align="center"><font face="verdana" size ="2" color="red">';
$uploadedfile = strtr($uploadedfile, "АБВГДЕабвгдеТУФХЦШтуфхцшИЙКЛийклЗзМНОПмнопЩЪЫЬщъыьяСс", "aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn");
$ext = $uploadedfile_type;
$len = strlen($ext);
$dir = '../photos/'.$idalbum;
$pos = strpos($ext,'/')+1;

$extension = substr($ext, $pos, $len);              


if($extension == "pjpeg"){ $extension = "jpg"; }
if($extension == "PJPEG"){ $extension = "jpg"; }
if($extension == "jpeg"){ $extension = "jpg"; }
if($extension == "JPEG"){ $extension = "jpg"; }
if($extension != 'jpg' && $extension != 'JPG' && $extension !='png' && $extension != 'PNG')
{

unset($uploadedfile);
echo $l_Addphoto_err1.'<br>';
   echo '<a href="detailphoto.php?idalbum='.$idalbum.'" class="lien1"><b>'.$l_Retour.'</a></b>.</font>';
   exit();
}
if (file_exists("$dir/$uploadedfile"))
{
unset($uploadedfile);
echo $l_Addphoto_err2.'<br>';
   echo '<a href="detailphoto.php?idalbum='.$idalbum.'" class="lien1"><b>'.$l_Retour.'</a></b>.</font>';
   exit();

}

//if image exist, upload it in correct dir
if($uploadedfile <> 'none')
{
  if (!copy($uploaded, "$dir/$uploadedfile"))
  {
//display errors
   echo 'Server error (can\'t upload).<br>';
   echo '<a href="detailphoto.php?idalbum='.$idalbum.'" class="lien1"><b>'.$l_Retour.'</a></b>.</font>';
   exit();
  }
//or finish
  else
  {
   chmod("$dir/$uploadedfile", 0777 );

   $newfile = $idalbum.'_'.$uploadedfile;
   $newalbum = $nom_album[0];
   $newcat = $rowcat1[0];
   $date = date("Y-m-d");
   $sql = "INSERT INTO mcgallery_photo (file, idalbum, album, cat, add_date) VALUES('$newfile', $idalbum, '$newalbum', '$newcat', '$date')";
   mysql_query($sql);

   if ($extension == 'jpg' || $extension == 'JPG')  $image = ImageCreateFromJPEG('../photos/'.$idalbum.'/'.$uploadedfile);
   elseif ($extension == 'png' || $extension == 'PNG')  $image = ImageCreateFromPNG('../photos/'.$idalbum.'/'.$uploadedfile);

   $width = imagesx($image) ;
   $height = imagesy($image) ;
   $new_width = $thumb_width;
   $new_height = ($new_width * $height) / $width ;
   if ($gd_ver == 1)
   {
   $thumb = imagecreate($new_width,$new_height);
   imagecopyresized($thumb,$image,0,0,0,0,$new_width,$new_height,$width,$height);
   }
   elseif ($gd_ver == 2)
   {
   $thumb = imagecreatetruecolor($new_width,$new_height);
   imagecopyresampled($thumb,$image,0,0,0,0,$new_width,$new_height,$width,$height);
   }

  if ($extension == 'jpg' || $extension == 'JPG')  ImageJPEG($thumb, '../photos/'.$idalbum.'/small/'.$uploadedfile);
  elseif ($extension == 'png' || $extension == 'PNG') ImagePNG($thumb, '../photos/'.$idalbum.'/small/'.$uploadedfile);

  imagedestroy($image);

   $dir = '../photos/'.$idalbum;
   echo '<form method="post" enctype="multipart/form-data" action="detailphoto.php">';
   echo '<table border="0" align="center" cellspacing="1" cellpadding="3" bgcolor="#000000">';
   echo '<tr><td bgcolor="#DDDDDD" align="center" colspan="5"><font face="verdana" size="2" color="black">';
   echo $l_Addphoto.' <b>'.stripslashes($nom_album[0]).'</b></font></td>';
   echo '<td bgcolor="#000000" align="left"><input type="file" name="uploadedfile" size="30">';
   echo '</td>';
   echo ' <input type="hidden" name="idalbum" value="'.$idalbum.'">';
   echo ' <input type="hidden" name="album" value="'.stripslashes($nom_album[0]).'">';
   echo '<input type="hidden" name="func" value="two">';
   echo '<td bgcolor="#000000"><input type="submit" name="submitfile" value="OK"></td></tr>';
   echo '</table></form>';
  }
}

break;
echo '</td></tr></table>';
}
?>