Просмотр файла script/admin/uploadphoto.php

Размер файла: 7.76Kb
<?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;
}
include './header.php';

echo '<table border="0" cellspacing="1" callpadding="3" align="center">';
$connect= mysql_connect($host,$login,$pass);
mysql_select_db($base, $connect);

if ($act == $l_valid_ok)
{
$query="SELECT * FROM mcgallery_upload WHERE id='$id'";
$result=mysql_query($query);
$row = mysql_fetch_array($result);
 if (!copy('../upload/'.$row['file'], '../photos/'.$idalbum.'/'.$row['file']))
 {
 echo 'server error<br>';
 echo '<a href="uploadphoto.php?act=detail&id='.$id.'" class="lien1"><b>'.$l_Retour.'</b></a>';
 }
 else
 {
 $query="SELECT album, cat FROM mcgallery_photo WHERE idalbum='$idalbum'";
 $res = mysql_query($query);
 $row2 = mysql_fetch_array($res);
 $newfile = $idalbum.'_'.$row['file'];
 $newauthor = addslashes($row['author']);
 $newtitle = addslashes($row['title']);
 $newalbum = addslashes($row2['album']);
 $newdescr = addslashes($row['descr']);
 $newcat = addslashes($row2['cat']);
 $date = date("Y-m-d");
 $query = "INSERT INTO mcgallery_photo (file, idalbum, album, cat, title, author, email, url, descr, add_date) VALUES('$newfile', '$idalbum', '$newalbum', '$newcat', '$newtitle', '$newauthor', '$row[email]','$row[url]','$newdescr', '$date')";
 mysql_query($query);

$ext = strrchr($row["file"], '.');
if ($ext == '.jpg' || $ext == '.JPG')  $image = ImageCreateFromJPEG('../photos/'.$idalbum.'/'.$row["file"]);
elseif ($ext == '.png' || $ext == '.PNG')  $image = ImageCreateFromPNG('../photos/'.$idalbum.'/'.$row["file"]);

 $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 ($ext == '.jpg' || $ext == '.JPG')  ImageJPEG($thumb, '../photos/'.$idalbum.'/small/'.$row["file"]);
 elseif ($ext == '.png' || $ext == '.PNG') ImagePNG($thumb, '../photos/'.$idalbum.'/small/'.$row["file"]);

imagedestroy($image);

 $query = "DELETE FROM mcgallery_upload WHERE id='$id'";
 mysql_query($query);

 unlink('../upload/'.$row["file"]);

 echo '<tr><td><font face="verdana" size="2" color="black">'.$l_Photo.' '.$l_valide.'<br><br>';
 echo '<a href="uploadphoto.php" class="lien1"><b>'.$l_Retour.'</b></a></font></td></tr>';
 }
}

if ($act == $l_Suppr)
{
$query="SELECT file FROM mcgallery_upload WHERE id='$id'";
$result=mysql_query($query);
$row = mysql_fetch_array($result);

unlink('../upload/'.$row["file"]);

$query = "DELETE FROM mcgallery_upload WHERE id='$id'";
mysql_query($query);

echo '<tr><td><font face="verdana" size="2" color="black">'.$l_Photo.' '.$l_Supprim.'<br><br>';
echo '<a href="uploadphoto.php" class="lien1"><b>'.$l_Retour.'</b></a></font></td></tr>';
}

if ($act == $l_Retour || empty($act))
{
$query="SELECT id, file FROM mcgallery_upload";
$result=mysql_query($query);
$nbre= mysql_num_rows($result);
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="2" color="black">';
 if ($nbre == 0)
 {
 echo $l_uploadNo;
 }
 else
 {
 echo $nbre.' '.$l_photos.': </font></td><td bgcolor="#AAAAAA"><font face="verdana" size="2" color="black">';
 $i = 1;
  while ($row=mysql_fetch_array($result))
  {
  echo '<a href="uploadphoto.php?act=detail&id='.$row['id'].'" class="lien1"><b>'.$i.'</b></a>';
  echo '&nbsp;&nbsp;&nbsp;&nbsp;';
   if ($i % 15 == 0) echo '<br>';
  $i++;
  }
 }
echo '</font></td></tr>';
}
if ($act =='detail')
{
$query="SELECT * FROM mcgallery_upload WHERE id='$id'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);

$query="SELECT album FROM mcgallery_photo WHERE idalbum='$row[idalbum]'";
$res = mysql_query($query);
$lig = mysql_fetch_array($res);
$query="SELECT album, idalbum FROM mcgallery_photo GROUP BY idalbum ORDER BY idalbum";
$resultat=mysql_query($query);


$size = ceil((filesize("../upload/$row[file]") / 1024));
$sizes = getimagesize("../upload/$row[file]");
echo '<form method="post" action="uploadphoto.php">';
echo '<tr>';
echo '<td bgcolor="#AAAAAA" colspan="2"><img src="../upload/'.$row['file'].'" border="0" alt=""></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Fichier.':</font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$row['file'].'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Size.':</font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$size.' ko</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Width.':</font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$sizes[0].'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Height.':</font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$sizes[1].'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Auteur.': </font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.stripslashes($row['author']).'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Email.': </font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$row['email'].'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Site.': </font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$row['url'].'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Titre.': </font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.stripslashes($row['title']).'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Description.': </font></td>';
echo '<td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.nl2br(stripslashes(htmlspecialchars($row['descr']))).'</font></td></tr>';
echo '<tr><td bgcolor="#AAAAAA"><font face="verdana" size="1" color="black">'.$l_Album.': </font></td>';
echo '<td bgcolor="#AAAAAA">';
echo '<select name="idalbum">';
echo '<option value="'.$row['idalbum'].'">'.$row['idalbum'].' - '.stripslashes($lig['album']).'</option>';
echo '<option value="">--------</option>';
 while ($row2=mysql_fetch_array($resultat))
 {
 echo '<option value="'.$row2['idalbum'].'">'.$row2['idalbum'].' - '.stripslashes($row2['album']).'</option>';
 }
echo '</select>';
echo '</td></tr>';
echo '<tr><td bgcolor="#AAAAAA" align="center" colspan="2"><font face="verdana" size="2" color="black">';
echo '<input type="hidden" name="id" value="'.$id.'">';
echo '<input type="submit" name="act" value="'.$l_valid_ok.'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
echo '<input type="submit" name="act" value="'.$l_Retour.'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
echo '<input type="submit" name="act" value="'.$l_Suppr.'"></td></tr>';
echo '</form>';
}

echo '</table>';
include './footer.php';
?>