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
Career Change into SAP
Hai
I am sajesh ,did my diploma in Mechatronics i have a 4 years of experience in
Add User script "Could not execute query"
This should be an easy script but I can't get it to run. Can someone please help me?
<
upload form file types....
Hey all, I am learning PHP and I am writing a script from the W3C Schools tutorials for uploading fi
Unexpected T_Variable ?
Hi all,
I dont really know what I am doing!! I know I'm doing something wrong, and I know its on
Multidimensional Array into an Html table, help!
Hello all, I am new to HTML/PHP so any help would be great.
I have a multidimensional array f
asp authentication problem
Hello all,
I want to use the asp authentication (from asp.net configuration) in my web site. there
Material xxx does not exist in plant xxx
Dear All,
I am working for a steel project which is repetitive manufacturing.
Share admin accross websites
I'm using .net memberships and roles in one of my sites, but I need to be able to share logins and p
Rounding a number queried from a database
I know that to display a rounded number you just do echo "round($number)";. But how would
Taking an HTML form and a PHP program and making it into one working file.
Hello,
So I would like to display everything INSIDE a specific directory. In other words, I