PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



uploading multiple images

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General
View previous topic :: View next topic  
Author Message
msbatt



Joined: 23 Nov 2009
Posts: 6

PostPosted: Mon Nov 30, 2009 4:23 pm    Post subject: uploading multiple images Reply with quote

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:1]<?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 } ?>
[/code:1]

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
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 6059
Location: toronto, canada

PostPosted: Mon Nov 30, 2009 5:18 pm    Post subject: Reply with quote

this is a [url=http://articles.sitepoint.com/article/php-gallery-system-minutes#]great article on multiple uploads with code[/url]
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
msbatt



Joined: 23 Nov 2009
Posts: 6

PostPosted: Mon Nov 30, 2009 7:13 pm    Post subject: Reply with quote

thanks
Back to top
View user's profile Send private message
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



PHP Code Examples
 Stream diffrent sizes of images from a single image to save disk space.
 JavaScript dropdown list menu to switch any page.
 Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
 PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
 Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
 Building a Dynamic Form using Javascript and innerHTML. Add form elements in realtime without refreshing the page.
 A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum