Jump to content

[SOLVED] multiple file upload and store names in db


realjumper

Recommended Posts

Hi,

 

I have a file upload form on the company website which stores the file in the 'uploads' directory and also store the filename in the db. Everything is good. Now they want (wouldn't you know it?!) a mulitple file upload instead. So I have a script, that I didn't create and I don't fully comprehend yet, that does the multi uploads just fine, but doesn't have the facility to enter the file names in the db. When the files are uploaded, I get a message which says (for example):

File: 44_1177360132.doc successfully uploaded!

File: test.doc successfully uploaded!

 

What I want to do is grab those file names and insert then into the db. I know (more or less) to place the insert query, but I don't know what to loop through to grab the file names?

 

Below is the form part of the page, and below that is the 'action' part of the page.

 

If anyone can help me out I will be gratefull ..... and happy!!!

 

The html form part of the page:


<p>Max. filesize = <?php echo $max_size; ?> bytes. (each) </p>
<form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>">
  <label for="upload[]">File 1:</label>
  <input type="file" name="upload[]" size="30"><br>
  <label for="upload[]">File 2:</label>
  <input type="file" name="upload[]" size="30"><br>
  <label for="upload[]">File 3:</label>
  <input type="file" name="upload[]" size="30"><br>
  <!-- Add here more file fields if you need. -->
  Replace files? 
  <input type="checkbox" name="replace" value="y">
  <input type="submit" name="Submit" value="Submit">
</form>

 

Here's the action part of the page:

 


if(isset($_POST['Submit'])) {
$multi_upload->tmp_names_array = $_FILES['upload']['tmp_name'];
$multi_upload->names_array = $_FILES['upload']['name'];
$multi_upload->error_array = $_FILES['upload']['error'];
$multi_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
$multi_upload->upload_multi_files();

}

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.