It is currently Wed Feb 08, 2012 5:10 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: uploading multiple images
PostPosted: Mon Nov 30, 2009 5:23 pm 
Offline

Joined: Mon Nov 23, 2009 6:16 pm
Posts: 6
Please can somebody help me with this script.

I'm developing a property website where the client can add a property to the database using the following script:

Code:
<?php
   $topPage = "siteContent/index";
   require_once "menu.php";

   if($_POST['submit']) {
      // Strip out the crap
      foreach($_POST as $key=>$value) {
         $formData[$key] = mysql_escape_string($value);
      }
      array_pop($formData); // Get rid of the submit button value

      // Check that the title and content are not empty
      if(($formData['ref'] != "") and ($formData['location'] != "")) {
         $formData['created'] = strtotime($formData['created']);

         // Check if we are updating or inserting a new user
         if($formData['id']) {
            mysql_query("UPDATE properties SET created = FROM_UNIXTIME(" . $formData['created'] . "), ref = '" . $formData['ref'] . "', fulldescription = '" . $formData['fulldescription'] . "', price = '" . $formData['price'] . "', location = '" . $formData['location'] . "', town = '" . $formData['town'] . "' WHERE id = " . $formData['id']);
         } else {
            mysql_query("INSERT INTO properties (ref, fulldescription, price, location, town, created) VALUES ('" . $formData['ref'] . "', '" . $formData['fulldescription'] . "', '" . $formData['price'] . "', '" . $formData['location'] . "', '" . $formData['town'] . "', FROM_UNIXTIME(" . $formData['created'] . "))");
            $formData['id'] = mysql_insert_id();
         }         
         $_POST['fileName'] = time();

         // Check that the name is not empty
         $imageName = basename($_FILES['newPicture']['name']);
         $extension = strtolower(substr($imageName, strlen($imageName) - 3));
         if($extension == "peg") $extension = "jpg";
            
         $destination = DOCUMENT_ROOT . STATIC_IMAGES_DIR . "/" . "property" . $formData['id'] . "." . $extension;
   
         if($_FILES['newPicture']['name'] != "") {
            if(move_uploaded_file($_FILES['newPicture']['tmp_name'], $destination)) {
               chmod($destination, 0777);
               mysql_query("UPDATE properties SET ext = '" . $extension . "' WHERE id = " . $formData['id']);
            }
         }

         doJSRedirect("properties.html", "");
         $STOP_DISPLAY = true;
      } else {
         doMessage("warning", "<strong>You must enter a reference and location for this letting.</strong><br/>Please complete the missing information below and click 'Save'.");
      }
   } else {
      $requestURI = end(explode("id=", $_SERVER['REQUEST_URI']));
      if(strip_tags($requestURI) != "") {
         if($lettings = mysql_query("SELECT *, UNIX_TIMESTAMP(created) AS created FROM properties WHERE id = " . $requestURI)) {
            $formData = mysql_fetch_assoc($lettings);
         } else {
            $formData['created'] = time();
         }
      }
   }

   if(!$STOP_DISPLAY) {
?>
      <h2>Edit Letting</h2>
      <form class="editForm" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="multipart/form-data">
         <input type="hidden" name="id" value="<?php echo $formData['id']; ?>"/>
         <input type="hidden" name="created" value="<?php echo niceDate($formData['created']); ?>"/>

         <label>Ref</label>
         <input class="text" type="text" name="ref" value="<?php echo $formData['ref']; ?>"/>

         <label>Street</label>
         <input class="text" type="text" name="location" value="<?php echo $formData['location']; ?>"/>

         <label>Town/City</label>
         <input class="text" type="text" name="town" value="<?php echo $formData['town']; ?>"/>
<div></div>
         <label>Image</label>
         <input type="file" name="newPicture" id="newPicture"/>
<div></div>
         <label>Price per month</label>
         <input class="text" type="text" name="price" value="<?php echo $formData['price']; ?>"/>
<div></div>
         <label>Full description</label>
         <textarea name="fulldescription"><?php echo $formData['fulldescription']; ?></textarea>
<div></div>
<input class="button" type="submit" name="submit" value="Save"/>
      </form>
<?php } ?>


This script works fine but it will only allow the user to add 1 image per property.
I need to adapt the script so that the following requirements can be met:
- up to 4 images can be added for each property
- each image is renamed 'image1', 'image2' etc. so they can be referenced individually on the 'property details' page on the front-end of the website

Any help would be greatly appreciated!!!

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 30, 2009 6:18 pm 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6500
Location: toronto, canada
this is a great article on multiple uploads with code

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 30, 2009 8:13 pm 
Offline

Joined: Mon Nov 23, 2009 6:16 pm
Posts: 6
thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to: