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
iterating through an array and escape each value independently.
I have a set up where the variable being escaped is an array and it needs to be iterated and escaped
Phase Error I can't seem to find :(`
Hey guys, I can seem to find my phase error on this. I am getting this error
[error]
Pars
Issue Parsing XML into table
Hello all,
Im a bit new to php and new to phpfreaks. But thanks in advance for the help!
<
Something like an INI editor or a DelimitedText-Editor
Hi all,
Am very, very, very new to PHP and not sure if I should be posting this to a Javascri
Dynamic Data + Sql Server 2005 Enterprise?
Hi! I have just started to learn ASP.NET, and it looks like it is quite a lot to learn. Im not reall
Simple program to copy files between two computers over the web
I use logmein free and often need to move files between my two computers. Generally, I move the file
Working with popups and such in a class
I've recently started building my applications completely enclosed in classes. I like the fact that
urldecode question
How would I format this line of code properly?
<?php echo urldecode($_GET['Title']); ?
whats wrong with my code please help!!!
this is the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link res
Passing vars to the DB
I have 3 small testing tables:
ID TYPE
1 pepperoni
2 C. bacon
3 taco
ID TY