Jump to content

Uploading/Downloading multiple files


gavenf

Recommended Posts

Hi all,

 

This is going to be another one of those questions that I am sure you have all had a million times.  Sadly I am only new to PHP and have reached a place I cant seem to get over.

 

I have a database "planitteacher" into which I would like to create a table that will allow me to put in the following:

 

Title

Description

Subject

Age Group

Date added

Email

File - This may have multiple files attached.

 

Basically the db is goign to be for teachers to share lesson plans with each other.  they can upload information about the lesson along with multiple files associated with the lesson such as images, PDF, DOC fiels etc.

 

I have already figured out how to make one form that uploads information to a test table called "uploads" and the code looks like this:

 

------------------------------------------------------------------------------------------------------

<html>

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Description</title>

</head>

 

<body>

<form method="post" action="upload4.php" enctype="multipart/form-data">

Title:<br>

<input type="text" name="form_title" size="40">

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<p>Description:</p>

<p>

<input type="text" name="form_description" size="40"></p>

<p>

Curriculum:</p>

<p>

          <font face="Arial" size="2">

          <select name="form_class" size="1">

          <option value="Pre-School">PreSchool</option>

<option value="Prep">Prep</option>

<option value="Grade 1">Grade 1</option>

<option value="Grade 2">Grade 2</option>

<option value="Grade 3">Grade 3</option>

<option value="Grade 4">Grade 4</option>

<option value="Grade 5">Grade 5</option>

<option value="Grade 6">Grade 6</option>

<option value="Year 7">Year 7</option>

<option value="Year 8">Year 8</option>

<option value="Year 9">Year 9</option>

<option value="Year 10">Year 10</option>

<option value="Year 11">Year 11</option>

<option value="Year 12">Year 12</option>

<option value="Special Needs">Special Needs</option>

<option value="Other">Other</option>

          </select></font></p>

<p>

Subject Area:</p>

<p>

          <font face="Arial" size="2">

          <select  name="form_subject" size="1">

          <c="Aboriginal Studies ">Aboriginal Studies </option>

<option value="Accounting ">Accounting </option>

<option value="Agriculture ">Agriculture </option>

<option value="Biology ">Biology </option>

<option value="Business Services ">Business Services </option>

<option value="Business Studies ">Business Studies </option>

<option value="Ceramics ">Ceramics </option>

<option value="Chemistry ">Chemistry </option>

<option value="Computing Applications ">Computing Applications </option>

<option value="Community & Family Studies ">Community & Family Studies </option>

<option value="Construction ">Construction </option>

<option value="Dance ">Dance </option>

<option value="Design & Technology ">Design & Technology </option>

<option value="Drama ">Drama </option>

<option value="Entertainment ">Entertainment </option>

<option value="Exploring Early Childhood ">Exploring Early Childhood </option>

<option value="Earth and Environmental Science ">Earth and Environmental Science </option>

<option value="Economics ">Economics </option>

<option value="Electronics Technology ">Electronics Technology </option>

<option value="Engineering Studies ">Engineering Studies </option>

<option value="English ">English </option>

<option value="Food Technology ">Food Technology </option>

<option value="Furnishing ">Furnishing </option>

<option value="Geography ">Geography </option>

<option value="History ">History </option>

<option value="Hospitality ">Hospitality </option>

<option value="Industrial Technology ">Industrial Technology </option>

<option value="Information Processes and Technology ">Information Processes and Technology </option>

<option value="Information Technology ">Information Technology </option>

<option value="Languages ">Languages </option>

<option value="Legal Studies ">Legal Studies </option>

<option value="Life Skills Courses - Special Program of Study ">Life Skills Courses - Special Program of Study </option>

<option value="Marine Studies ">Marine Studies </option>

<option value="Mathematics ">Mathematics </option>

<option value="Metal & Engineering ">Metal & Engineering </option>

<option value="Music ">Music </option>

<option value="Personal Development, Health and Physical Education (PDHPE) ">Personal Development, Health and Physical Education (PDHPE) </option>

<option value="Photography, Video and Digital Imaging ">Photography, Video and Digital Imaging </option>

<option value="Physics ">Physics </option>

<option value="Primary Industries ">Primary Industries </option>

<option value="Retail ">Retail </option>

<option value="Senior Science ">Senior Science </option>

<option value="Society and Culture ">Society and Culture </option>

<option value="Software Design & Development ">Software Design & Development </option>

<option value="Sport, Lifestyle and Recreation ">Sport, Lifestyle and Recreation </option>

<option value="Studies of Religion ">Studies of Religion </option>

<option value="Textiles & Design ">Textiles & Design </option>

<option value="Tourism ">Tourism </option>

<option value="Visual Arts ">Visual Arts </option>

<option value="Visual Design ">Visual Design </option>

<option value="Work Studies ">Work Studies </option>

          </select></font></p>

<p>

Web Link:</p>

<p>

<input type="text" name="form_web1" size="40"></p>

<p>

Email:</p>

<p>

<input type="text" name="form_email" size="40"><br> </p>

<p>

File to upload:<br>

<input type="file" name="form_data" size="40">

</p>

<p><input type="submit" name="submit" value="submit">

</form>

</body>

 

</html>

---------------------------------------------------

The PHP for the upload4.php file is:

---------------------------------------------------

<?php

mysql_connect("localhost","teacher","slider1234");

mysql_select_db("planitteacher");

$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));

$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype,title,subject,class,web1,email) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type','$form_title','$form_subject','$form_class','$form_web1','$form_email')");

$id= mysql_insert_id();

print "<p>File ID: <b>$id</b><br>";

print "<p>File Name: <b>$form_data_name</b><br>";

print "<p>File Size: <b>$form_data_size</b><br>";

print "<p>File Type: <b>$form_data_type</b><p>";

print "To upload another file <a href=http://www.somethinghere.com> Click Here</a>";

?>

-------------------------------------------------------------------

Currently the db only accepts one file with each upload.

What I want to know is how do I make the form accept multiple files and show them as they are added.  Then once they are in the Database make the db searchable, show the results then allow the files to be downloaded.

 

Hope someone can help

 

Link to comment
https://forums.phpfreaks.com/topic/45824-uploadingdownloading-multiple-files/
Share on other sites

If you want to allow multiple files uploaded in one hit you need to add more file elements to your form like

 

<input type="file" name="form_data[]" size="40">

<input type="file" name="form_data[]" size="40">

<input type="file" name="form_data[]" size="40">

 

see http://au2.php.net/manual/en/features.file-upload.php for a more complete explanation.

 

You should also make a separate table for storing information about the files since theres often going to be more than one file associated with a lesson plan.

 

e.g

 

table : lesson_plan

 

id

title

description

age_group

date_added

email_address

----------------------------

table : lesson_plan_files

 

id

lesson_plan_id (foreign key - the id of the record associated with this file)

file_name

file_type

file_size

file_data

 

 

Ok I added more elements but now it simply says Array in the file name File size and File type.  Also the data column says there is 0" data.

 

Not sure how to retireve this infortmation using a search. 

 

How do I make multiple tables inputable from one form?

 

-----------------------------

If you want to allow multiple files uploaded in one hit you need to add more file elements to your form like

 

<input type="file" name="form_data[]" size="40">

<input type="file" name="form_data[]" size="40">

<input type="file" name="form_data[]" size="40">

 

see http://au2.php.net/manual/en/features.file-upload.php for a more complete explanation.

 

You should also make a separate table for storing information about the files since theres often going to be more than one file associated with a lesson plan.

 

e.g

 

table : lesson_plan

 

id

title

description

age_group

date_added

email_address

----------------------------

table : lesson_plan_files

 

id

lesson_plan_id (foreign key - the id of the record associated with this file)

file_name

file_type

file_size

file_data

 

 

Sorry but I have no clue what your talkin about.  I am only new to this and I cant quite keep up with all the jargon.  I am learning though.

 

Do you have an example?

 

foreach ($file) { } will loop the specific files with their file names

 

well obviously not $file, but the array you're talking about

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.