Jump to content

dutchboy

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dutchboy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all thanks if you are taking time to read this. I have a problem with this script i am using and was wondering if anyone could help me out. I am creating a simple CMS and have managed to get the data entry for the site working very well with the original version of this script: <? session_start(); if(!session_is_registered(myusername)){ header("location:login.php"); } $id = $_GET['id']; $idir = "dbimages/"; $tdir = "dbimages/thimages/"; $twidth = "120"; $theight = "120"; $photo1=( $_FILES['photo1']['name']); $photo2=( $_FILES['photo2']['name']); $photo3=( $_FILES['photo3']['name']); $photo4=( $_FILES['photo4']['name']); $photo5=( $_FILES['photo5']['name']); mysql_connect("localhost", "user", "pass") or die(mysql_error()) ; mysql_select_db("db") or die(mysql_error()) ; mysql_query("UPDATE table SET photo1='$photo1', photo2='$photo2', photo3='$photo3', photo4='$photo4', photo5='$photo5' WHERE id='$id' ") ; $url1 = $_FILES['photo1']['name']; if ($_FILES['photo1']['type'] == "image/jpg" || $_FILES['photo1']['type'] == "image/jpeg" || $_FILES['photo1']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['photo1']['name'], '.'); $copy = copy($_FILES['photo1']['tmp_name'], "$idir" . $_FILES['photo1']['name']); if ($copy) { $simg = imagecreatefromjpeg("$idir" . $url1); $currwidth = imagesx($simg); $currheight = imagesy($simg); if ($currheight > $currwidth) { $zoom = $twidth / $currheight; $newheight = $theight; $newwidth = $currwidth * $zoom; } else { $zoom = $twidth / $currwidth; $newwidth = $twidth; $newheight = $currheight * $zoom; } $dimg = imagecreate($newwidth, $newheight); imagetruecolortopalette($simg, false, 256); $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($simg, $i); ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($dimg, "$tdir" . $url1); imagedestroy($simg); imagedestroy($dimg); } $url2 = $_FILES['photo2']['name']; if ($_FILES['photo2']['type'] == "image/jpg" || $_FILES['photo2']['type'] == "image/jpeg" || $_FILES['photo2']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['photo2']['name'], '.'); $copy = copy($_FILES['photo2']['tmp_name'], "$idir" . $_FILES['photo2']['name']); if ($copy) { $simg = imagecreatefromjpeg("$idir" . $url2); $currwidth = imagesx($simg); $currheight = imagesy($simg); if ($currheight > $currwidth) { $zoom = $twidth / $currheight; $newheight = $theight; $newwidth = $currwidth * $zoom; } else { $zoom = $twidth / $currwidth; $newwidth = $twidth; $newheight = $currheight * $zoom; } $dimg = imagecreate($newwidth, $newheight); imagetruecolortopalette($simg, false, 256); $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($simg, $i); ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($dimg, "$tdir" . $url2); imagedestroy($simg); imagedestroy($dimg); } $url3 = $_FILES['photo3']['name']; if ($_FILES['photo3']['type'] == "image/jpg" || $_FILES['photo3']['type'] == "image/jpeg" || $_FILES['photo3']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['photo3']['name'], '.'); $copy = copy($_FILES['photo3']['tmp_name'], "$idir" . $_FILES['photo3']['name']); if ($copy) { $simg = imagecreatefromjpeg("$idir" . $url3); $currwidth = imagesx($simg); $currheight = imagesy($simg); if ($currheight > $currwidth) { $zoom = $twidth / $currheight; $newheight = $theight; $newwidth = $currwidth * $zoom; } else { $zoom = $twidth / $currwidth; $newwidth = $twidth; $newheight = $currheight * $zoom; } $dimg = imagecreate($newwidth, $newheight); imagetruecolortopalette($simg, false, 256); $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($simg, $i); ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($dimg, "$tdir" . $url3); imagedestroy($simg); imagedestroy($dimg); } $url4 = $_FILES['photo4']['name']; if ($_FILES['photo4']['type'] == "image/jpg" || $_FILES['photo4']['type'] == "image/jpeg" || $_FILES['photo4']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['photo4']['name'], '.'); $copy = copy($_FILES['photo4']['tmp_name'], "$idir" . $_FILES['photo4']['name']); if ($copy) { $simg = imagecreatefromjpeg("$idir" . $url4); $currwidth = imagesx($simg); $currheight = imagesy($simg); if ($currheight > $currwidth) { $zoom = $twidth / $currheight; $newheight = $theight; $newwidth = $currwidth * $zoom; } else { $zoom = $twidth / $currwidth; $newwidth = $twidth; $newheight = $currheight * $zoom; } $dimg = imagecreate($newwidth, $newheight); imagetruecolortopalette($simg, false, 256); $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($simg, $i); ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($dimg, "$tdir" . $url4); imagedestroy($simg); imagedestroy($dimg); } $url5 = $_FILES['photo5']['name']; if ($_FILES['photo5']['type'] == "image/jpg" || $_FILES['photo5']['type'] == "image/jpeg" || $_FILES['photo5']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['photo5']['name'], '.'); $copy = copy($_FILES['photo5']['tmp_name'], "$idir" . $_FILES['photo5']['name']); if ($copy) { $simg = imagecreatefromjpeg("$idir" . $url5); $currwidth = imagesx($simg); $currheight = imagesy($simg); if ($currheight > $currwidth) { $zoom = $twidth / $currheight; $newheight = $theight; $newwidth = $currwidth * $zoom; } else { $zoom = $twidth / $currwidth; $newwidth = $twidth; $newheight = $currheight * $zoom; } $dimg = imagecreate($newwidth, $newheight); imagetruecolortopalette($simg, false, 256); $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($simg, $i); ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($dimg, "$tdir" . $url5); imagedestroy($simg); imagedestroy($dimg); header( 'Location:genxml.php' ) ; } else { print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; } } } } } } ?> This page is fed from a simple html form and uploads the pictures and creates the thumbnails on the fly and stores them on the server while adding the file name to my database along with the other info submitted. This works with no problems. I then needed to create another script that allowed me to delete the images by $id from the server which works, and now i would like to adjust the above script so that i can update the images and filenames only, into my database on the relevant field (by $id). For ex. I upload all the details one day( including images ), and the next day i want to change all the images so i run my delete image script against the id ($id) and it deletes the images from the folders on the servers. I then want to choose 5 different images and upload them and add the filenames to an existing database entry. So I delete that particular entries images and carry on. However, as i changed my query to 'update' (in the code above) from 'insert into' (from the original upload page) the filenames do not update in the database, although the images are still uploaded and thumbnails created ect... I am having no problems updating other info through my CMS just this problem with adding new/different image filenames to an existing entry. Sorry this is long, hope i have been clear enough. Thanks.
  2. ok scratch the above message the script above works like a charm!! thank you so much Chris92 ive been struggling with this one! really can't thank you enough!
  3. Wow quick response thanks! Please forgive my stupidity could you ellaborate a little more on "maybe it would be easier just to store all the info in the database and just get the image id to be deleted from the query string" do you mean actually upload the pictures into the database?
  4. Hope someone can help. I have an upload script which uploads images and creates a thumbnail and puts them into seperate thumbnail/fullimage folders on the server and adds the file name to my sql database. I have built a simple CMS which enables me to edit individual rows on a database and delete rows using this script <?php include("config.php"); $id = $_GET['id']; $result = mysql_query("DELETE FROM markers WHERE id='$id' ",$connect); header( 'Location:genxml.php' ) ; ?> The id is obtained by passing the variable through a hyper link on my "database manager" page. This works well and deletes the particular entry from the database but does'nt deal with the images stored on the server. I was hoping to pass more variables through my hyperlink so that i can use the unlink function in the above script but dont know if this would work. Below is an attempt which might clear things up a little. <?php include("config.php"); $imagedir = "dbimages/"; $thumbnaildir = "dbimages/thimages/"; $id = $_GET['id']; $pic1del = "$imagedir" . $_GET['photo1']; $thumb1del = "$thumbnaildir" . $_GET['photo1']; unlink($pic1del); unlink($thumb1del); $result = mysql_query("DELETE FROM markers WHERE id='$id' ",$connect); header( 'Location:genxml.php' ) ; ?> from link <a href=delete.php?id=$id&photo1=$photo1>Delete</a> so as you can see i want to pass my image names to the delete page, add the file path and delete the images as well as the database row...... but i dont know if im going about it the correct way as im a noob to php. (thumbnail is named the same as the original image which is why i call 'photo1' twice, just saved in the different folders!) hope someone can help, thanks in advance.
  5. Hi everyone, great forum you have here! Anyway i hope someone may be able to help!!! The script below allows me upload 1 image and create a thumbnail as well as adding the file name and other info from my form to my database! Lovely it works a charm and allows me to do everthing i want. However, is there a way i can adapt the script to allow multiple uploads, i know about extending the fields to accept new file names ect, its just the upload and thumbnail part of the script to accept more than one image at time. Thanks in advance for taking the time to read this, any help would be greatly appreciated. $idir = "dbimages/"; $tdir = "dbimages/thimages/"; $twidth = "120"; $theight = "120"; $lat=$_POST['lat']; $lng=$_POST['lng']; $type=$_POST['type']; $address=$_POST['address']; $beds=$_POST['beds']; $name=$_POST['name']; $pic=( $_FILES['photo']['name']); mysql_connect("dbserver", "dbuser", "dbpass") or die(mysql_error()) ; mysql_select_db("dbname") or die(mysql_error()) ; mysql_query("INSERT INTO `dbtable` (lat, lng, type, address, beds, name, photo) VALUES ('$lat', '$lng', '$type', '$address', '$beds', '$name', '$pic')") ; $url = $_FILES['photo']['name']; if ($_FILES['photo']['type'] == "image/jpg" || $_FILES['photo']['type'] == "image/jpeg" || $_FILES['photo']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['photo']['name'], '.'); $copy = copy($_FILES['photo']['tmp_name'], "$idir" . $_FILES['photo']['name']); if ($copy) { $simg = imagecreatefromjpeg("$idir" . $url); $currwidth = imagesx($simg); $currheight = imagesy($simg); if ($currheight > $currwidth) { $zoom = $twidth / $currheight; $newheight = $theight; $newwidth = $currwidth * $zoom; } else { $zoom = $twidth / $currwidth; $newwidth = $twidth; $newheight = $currheight * $zoom; } $dimg = imagecreate($newwidth, $newheight); imagetruecolortopalette($simg, false, 256); $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { $colors = ImageColorsForIndex($simg, $i); ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($dimg, "$tdir" . $url); imagedestroy($simg); imagedestroy($dimg);
×
×
  • 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.