Amend code to allow multiple attachments


Posted on 16th Feb 2014 07:03 pm by admin

Hi

I have a php page that allows the user to browse to a file (image) then sumbit, the confirmation page then has the following code which uploads the said file to the hosting server, but also appends a unique number (WOref) to the file name and saves some other information to a MYSQL database. It also confirms the upload by showing a preview of the image. What I want is to allow at the browse for file stage, for it to select more than one file, and then upload those files using the same principles below. Any ideas?


Extract from Initial page with file browse button and area:

<input type="file" name="photo">



Extract from Confirmation page of the code which uploads file etc:
<?php
//This gets all the other information from the form
$name=$_POST['WOref'];
$pic=($_FILES['photo']['name']);

//This is the directory where images will be saved
$target = "uploads/";
$target = $target .$name. basename( $_FILES['photo']['name']);

mysql_query("INSERT INTO `attachments` VALUES ('$name','$pic','$target',current_timestamp)") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file " .$pic. basename($_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

<?php chmod( $target , 0644 );?>

<img src="<?php print $target; ?>">



Many many thanks.

No comments posted yet

Your Answer:

Login to answer
258 Like 9 Dislike
Previous forums Next forums
Other forums

keeps going back to index.html ???????
ok so i started making my site using mostly.html files now i have added a fair chunk of php. My inde

in php, link returns to the line
When I add a link in a php page, the link word returns to the line (as a
would do)

Examp

How to know if online site made with PHP
Hello,
I see some sites that does not display extensions at all , for example:

www.site.co

Working with popups and such in a class
I've recently started building my applications completely enclosed in classes. I like the fact that

Login script (probably a simple error)
dbConfig.php
Code: <?
// Replace the variable values below
// with your specific dat

Session login issue
I'm wondering how to fix a problem I'm having with a session-based login system

Say I go to h

i want run some web server under the ip sharer
hello i want run some web server under the ip sharer
my ip is floating ip but it doesnt matter

text box alphanumeric caracters only
hi all!

I have search on google on how to enter in a test box only caracters A-Z,a-z,0-9 usi

Multi Level Array Problem
hi all,

For example I have array like below:

$temp = array(array('north america', 'us'

need help with date function
i have following form for date

Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash