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

Change of partner analyse in sales orders
Hello,

I changed the partner analyse for sales orders and added a new mandatory partnerro

sql error
I have been looking at this code for 20mins and can't work out what I am doing wrong. There is somet

distinct rows
Hi
version 10.2.0.3

I have a query output something like the following

ID

Lining up columns nicely.
Hello everyone, I'm having problems with making columns line up properly. Here is my code:

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

Extra fields in main body and php required.
I'm new to PHP so please be gentle. I have a little php script below that works well.
The &quo

Setting/Modify Headers using mail() function
I have a question about setting email headers when using mail() in a php script.

When I send

HTML Email rec'd as Source Code
The code does create and send the email successfully. However, the message shows as html code and n

Packet Design
Hi All,
Im new about network programming and I want to design a protocol but I have some question

Parse error: syntax error, unexpected $end in
hello,
i receive the error :Parse error: syntax error, unexpected $end in C:xamppxampphtdocsh

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