Jump to content

Photo Upload / Delete PHP help


craigeves

Recommended Posts

Hello PHP Freaks!

 

Can anyone help me?

 

I have a script that can connect to mySQL, upload an image to a directory on the server and is also deleteable via the admin panel if required (then another image can be uploaded to replace it).

 

The problem is that it is only capable of doing this to 1 image.

 

Is there anyway of adjusting this to work with 10 images? Here is my script. It must also be able to connect to my current database and create a new database table - not using the existing one.

 

edit_content_script.php - this is the upload form

<?php

session_start();

extract($_REQUEST, EXTR_OVERWRITE);

include ("func.php");



$uname= $_SESSION['uname'];

$upass= $_SESSION['upass'];



if(!auth_adm($uname, $upass)>0)

header('Location:logadm.php?err=1');

$adminid=auth_adm($uname, $upass);



?>

<form action="editcontent_script.php" method="post" enctype="multipart/form-data">
  <table width="800">
    <tr>
      <td width="150" class="rowHeaders">Photo Upload
      <td><? if(empty($row['photo'])){?>
        <input type=file name="photo1">
        <?} else {?>
        <a href=remove1.php class="links">Delete Current Photograph</a>
        <?}?>
    <tr>
      <td><input type=submit value="Submit" class="button">
  </table>
</form>

 

editcontent_script.php - this is the script that does the magic

<?php

session_start();

extract($_REQUEST, EXTR_OVERWRITE);

include ("func.php");



$uname= $_SESSION['uname'];

$upass= $_SESSION['upass'];



if(!auth_adm($uname, $upass)>0)

header('Location:logadm.php?err=1');

$sql="select photo_path,width from rsvp_set";
$rez=mysql_query($sql,$dblnk);
$row=mysql_fetch_array($rez);
$folder=$row['photo_path'];

$adminid=auth_adm($uname, $upass);
for ($num=1;$num<=1;$num++){

	@move_uploaded_file($_FILES['photo'.$num]['tmp_name'], "./".$folder."/photo1.jpg");
	//$photo1= $_FILES['photo'.$num]['name'];
	$photo1="photo.jpg";
	$image_path="./".$folder."/photo1.jpg";
	$thumb_path="./".$folder."/photo.jpg";
	$thumb_width=$row['width'];
	$thumb_height=0;
	createthumbnailjpg($image_path,$thumb_path,$thumb_width,$thumb_height);

}


$content=mysql_escape_string(stripslashes($content));

$date=$year."-".$month."-".$day;
$sql="update rsvp_set set regintro='$regintro', content='$content', content2='$content2', heading='$heading',wedding_date='$date',photo='$photo1'";
$rez=mysql_query($sql,$dblnk);

header('location: edit_content.php');
?>

 

func_script.php - not sure if this is needed or not

<? include ("define.php");


function auth_adm($uname, $upass)
{
global $dblnk;
$sql="select id from admin where uname='$uname' and upass='$upass'";
//echo $sql;
$rez=mysql_query($sql,$dblnk);//echo $rez;
//$row=mysql_fetch_array($rez);
$nr=mysql_num_rows($rez);
$row=mysql_fetch_array($rez);
$ok=$row['id'];
//if ($nr!=0)$ok=1;
//else $ok=0;
return $ok;

} //end auth

function status($status)
{
if($status==0) $mesg="<font color=red>Unread</font>";
if($status==1) $mesg="Read";

return $mesg;	
}


function resizeCreatedImage(&$src_img,$outWidth,$outHeight)
{
   $srcWidth=imagesx($src_img);
   $srcHeight=imagesy($src_img);
      if(!$outHeight || $outHeight=='') $outHeight=$outWidth;
   $imgOut=imagecreatetruecolor($outWidth,$outHeight);
  //imagerectangle($imgOut,0,0,$outWidth,$outHeight,imagecolorallocate($imgOut,255,255,255));
      $xoffset = 0;
   $yoffset = 0;
   if ($srcWidth*$outHeight > $srcHeight*$outWidth)
   {
       $xtmp = $srcWidth;
       $xratio = 1-((($srcWidth/$srcHeight)-($outWidth/$outHeight))/2);
       $srcWidth = $srcWidth * $xratio;
       $xoffset = ($xtmp - $srcWidth)/2;
   }
   elseif ($srcHeight/ $outHeight > $srcWidth / $outWidth)
   {
       $ytmp = $srcHeight;
       $yratio = 1-((($outWidth/$outHeight)-($srcWidth/$srcHeight))/2);
       $srcHeight = $srcHeight * $yratio;
       $yoffset = ($ytmp - $srcHeight)/2;
   }

   imagecopyresampled($imgOut, $src_img, 0, 0, $xoffset, $yoffset, $outWidth, $outHeight, $srcWidth, $srcHeight);
        return $imgOut;
}

function createthumbnailjpg($image_path,$thumb_path,$thumb_width,$thumb_height=0)
{
   $src_img = imagecreatefromjpeg($image_path);
    $dst_img = resizeCreatedImage($src_img,$thumb_width,$thumb_height);
   imagejpeg($dst_img, $thumb_path);
   return true;
}
function createthumbnailpng($image_path,$thumb_path,$thumb_width,$thumb_height=0)
{
   $src_img = imagecreatefrompng($image_path);
    $dst_img = resizeCreatedImage($src_img,$thumb_width,$thumb_height);
   imagepng($dst_img, $thumb_path);
   return true;
}
function createthumbnailgif($image_path,$thumb_path,$thumb_width,$thumb_height=0)
{
   $src_img = imagecreatefromgif($image_path);
    $dst_img = resizeCreatedImage($src_img,$thumb_width,$thumb_height);
   imagepng($dst_img, $thumb_path);
   return true;
} 


?>

 

 

remove1_script.php - this removes the image from the database

<?php

session_start();

extract($_REQUEST, EXTR_OVERWRITE);

include ("func.php");



$uname= $_SESSION['uname'];

$upass= $_SESSION['upass'];



if(!auth_adm($uname, $upass)>0)

header('Location:logadm.php?err=1');

$adminid=auth_adm($uname, $upass);


$sql="update rsvp_set set photo='' ";
$rez=mysql_query($sql,$dblnk);
header('location: edit_content.php');

?>

 

install_script.php - the install files

<?
include ("define.php");
$sql="CREATE TABLE `admin` (
  `id` int(11) NOT NULL auto_increment,
  `uname` text NOT NULL,
  `upass` text NOT NULL,
  `name` text NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=3 ";
$rez=mysql_query($sql,$dblnk);

$sql="INSERT INTO `admin` VALUES (1, 'user', 'pass', 'name')";
$rez=mysql_query($sql,$dblnk);

$sql="INSERT INTO `admin` VALUES (2, 'user2', 'pass2', 'name2')";
$rez=mysql_query($sql,$dblnk);

$sql="CREATE TABLE `event` (
  `id` int(11) NOT NULL auto_increment,
  `event` text NOT NULL,
  `event_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `location` text NOT NULL,
  `address` text NOT NULL,
  `city` text NOT NULL,
  `postcode` text NOT NULL,
  `rsvp` tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=14";
$rez=mysql_query($sql,$dblnk);


$sql="CREATE TABLE `event_people` (
  `id` int(11) NOT NULL auto_increment,
  `event` int(11) NOT NULL default '0',
  `name` text NOT NULL,
  `rsvp` tinyint(4) NOT NULL default '0',
  `notes` text NOT NULL,
  `phone` text NOT NULL,
  `email` text NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=20";
$rez=mysql_query($sql,$dblnk);

$sql="CREATE TABLE `rsvp_guest` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `message` text NOT NULL,
  `date_submitted` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=6  ";
$rez=mysql_query($sql,$dblnk);


$sql="CREATE TABLE `rsvp_set` (
  `id` int(11) NOT NULL auto_increment,
  `photo_path` text NOT NULL,
  `regintro` text NOT NULL,
  `content` text NOT NULL,
  `content2` text NOT NULL,
  `wedding_date` text NOT NULL,
  `photo` text NOT NULL,
  `heading` text NOT NULL,
  `width` text NOT NULL,
  `height` text NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2";
$rez=mysql_query($sql,$dblnk);

$sql="CREATE TABLE `list` (
  `id` int(11) NOT NULL auto_increment,
  `store` text NOT NULL,
  `reg_name` text NOT NULL,
  `url` text NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1";
$rez=mysql_query($sql,$dblnk);



$sql="INSERT INTO `rsvp_set` VALUES (1, 'images', '<p>regintro</p>', '<p>Hello, this is just a little test to see how well this wysiwyg tinymce editor works.</p>\r\n<p>Looks like it works just fine!</p>', '<p>test</p>', '2009-3-7', 'photo.jpg', 'Craig & Marie', '300', '0')";
$rez=mysql_query($sql,$dblnk);

if($rez==1) echo "Install successful, please remove install.php file.";
?>

 

Thanks so much

 

Craig

 

Link to comment
https://forums.phpfreaks.com/topic/111807-photo-upload-delete-php-help/
Share on other sites

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.