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
9
Other forums
button help
i originally had this but realised it is much easier to have a button.
Code: <?php
Problems with returning true or false in eval()'d code
Hi guys,
Would appreciate some help with a problem when running eval() on a function that sho
Code clarification
Hi
In the following code what could be the "search_print()" and where it could be
Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there
newbie question about multiple queries
hi everyone,
I'm sorry to ask such a basic question, but I'm young and trying to learn php on my
Need a fuction to count entries in a field
Hi
I need a fuction to count how many times a email address is entered in to a field.
I ma
cPanel API
Hi Guys,
Need a little guidance. I'm trying to get my script to communicate with cPanel (or W
how to make database item unique
Hey guys,
is it possible to do this:
I have the database item $title being pulled for
How to return to a previous page after running a PHP script
I'm having a bit of a melt down here because I think this should be really easy but can't work it ou
Problem with creating FI documents
Hi, Experts!
when i create Fi doc. with standart transaction, i ve been had such problem