Hi, I am developing a Lease Management System, and I need to upload multiple files in a folder. and I want to name the folder where I want to upload in DB.
Here is a code for upload a single file.
first file is sendfile.php

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30001" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

and upload.php file is

<?php


$uploaddir = $_SERVER['DOCUMENT_ROOT'] . "/other/";
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "Successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

print "</pre>";

?>

Its working now for multiple files
sendfile.php

<table width="98%" border="0" cellspacing="0" cellpadding="0">
<!-- The data encoding type, enctype, MUST be specified as below -->

<form enctype="multipart/form-data" action="upload.php" method="POST">
  <tr>
    <td><table width="98%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="14%"><span class="style7 style1">Upload LA:</span></td>
    <td width="86%"><!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="9999999" />
    <!-- Name of input element determines name in $_FILES array -->
     <input name="userfile" type="file" style="border-width: 1px;
    border-style: solid;
    border-color: #61A0CE;
	background-image: url(b.jpg);
    background-repeat: no-repeat;
	background-position: center;
	font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #333333;
    width: 250px;
    height: 20px;" /><br /></td>
  </tr>
  <tr>
    <td><span class="style7 style1">Upload PO</span></td>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="9999999" />
	  <input name="userfile1" type="file" style="border-width: 1px;
    border-style: solid;
    border-color: #61A0CE;
	background-image: url(b.jpg);
    background-repeat: no-repeat;
	background-position: center;
	font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #333333;
    width: 250px;
    height: 20px;" /><br /></td>
  </tr>
  <tr>
    <td><span class="style7 style1"> Upload SPA: </span></td>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="9999999" />
	 <input name="userfile2" type="file" style="border-width: 1px;
    border-style: solid;
    border-color: #61A0CE;
	background-image: url(b.jpg);
    background-repeat: no-repeat;
	background-position: center;
	font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: #333333;
    width: 250px;
    height: 20px;" /></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" value="Send Files" /> </td>
    </tr>
   
</table>
</td>
  </tr>
  </form>
</table>

and upload page is

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = $_SERVER['DOCUMENT_ROOT'] . "/LA/";
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$uploaddir1 = $_SERVER['DOCUMENT_ROOT'] . "/PO/";
$uploadfile1 = $uploaddir1 . basename($_FILES['userfile1']['name']);
$uploaddir2 = $_SERVER['DOCUMENT_ROOT'] . "/SPA/";
$uploadfile2 = $uploaddir2 . basename($_FILES['userfile2']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "LA Successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

/*echo 'Here is some more debugging info:';
print_r($_FILES);*/

print "</pre>";
echo '<pre>';
if (move_uploaded_file($_FILES['userfile1']['tmp_name'], $uploadfile1)) {
    echo "PO Successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

/*echo 'Here is some more debugging info:';
print_r($_FILES);*/

print "</pre>";

echo '<pre>';
if (move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)) {
    echo "SPA Successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

/*echo 'Here is some more debugging info:';
print_r($_FILES);*/

print "</pre>";

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.