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?

Did you know?Explore Trending and Topic pages for more stories like this.

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

How would I protect......
I have a from, actually, a good amount of forms. How can I make it so you can't type the characters:

I didnt code this but I need help with it
I'm sorry. i'm not a coder. I have this script for forcing download and previewing mp3. The guy that

get multiple rows
Hi I want to get multiple rows from a db

I am using this for the db query
Code: public

Get word number x from string?
How can I use a function to loop through a string, and "have a look at" every word in the

List/Menu Box
On an edit page when you want something to select what a user has previously selected from the datab

uploading video files into mysql in php
hi,
I have the video files which i have to upload into mysql db. along with creating thumbnails f

PHP header help!
Hi all I am trying to get this php page to refresh every 5 seconds on my phone which is an aastra 48

Impact of movement type 412 E on MAP
Hi

Usage of movement type 412 E is causing huge change in MAP .

Is there any r

Help Ordering Arrays
Hi, I have 3 arrays as shown below.

Code: $users = $this->get_latest_users();
$flir

for some reason mysql query not working, not inserting, please check it out
This code is not inserting anything into my db, don't know why, the $_SESSION variable does contain

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