Multiple Files Upload into Multiple Folders
The following folders should be created in your web root
- accountant
- deputy_director
- Administrative_officer
Following HTML file is used to upload files to above 3 folders.
Upload To All
|
<html> <head> <title>UPload Multiple file</title> </head> <body> <center><h2>Upload To All </h2></center> <form action="upload4.php" method="post" enctype="multipart/form-data" name="form1" id="form1" > <tr><td> <table align="center"> <tr><td colspan=2><hr></hr></td></tr> <tr> <td><strong>multiple Files Upload </strong></td> </tr> <tr><td>Title</td></tr> <tr><td><input type="text" name="txtName"></td></tr> <tr> <td>Select file <input name="ufile" type="file" id="ufile" size="50" /></td> </tr> <tr><td><input name="sender" type="hidden" value="Director"></td></tr> <tr><td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </form> <tr><td colspan=2><hr></hr></td></tr> </table> </body> </html> |
This uploaded files details are sent to a data base.Make 3 tables accountant, deputy_director and Administrative_officer in my_database which you have practiced in early lessens.Fields are stated in the below file for Administrative_officer table only.
CREATE TABLE IF NOT EXISTS `Administrative_officer` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `date` varchar(60) NOT NULL, `time` varchar(45) NOT NULL, `Name` varchar(100) NOT NULL, `file` varchar(100) NOT NULL, `sender` varchar(45) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; |
upload4.php which carries uploaded 3 files to 3 folders is as follows
<?php $path1= "accountant/".$_FILES['ufile']['name']; $path2="deputy_director/".$_FILES['ufile']['name']; $path3="Administrative_officer/".$_FILES['ufile']['name']; $date = date("y/m/d"); $time = date("g:i a"); $file_name = $_FILES['ufile']['name']; $random_digit=rand(0000,9999); $new_file_name=$random_digit.$file_name; $path1= "accountant/".$new_file_name; if($file !=none) { if(copy($_FILES['ufile']['tmp_name'], $path1)) { mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("my_database"); $strSQL = "INSERT INTO accountant"; $strSQL .="(date,time,Name,file,sender) VALUES ('$date','$time','".$_POST["txtName"]."','$new_file_name','".$_POST["sender"]."')"; mysql_query($strSQL); echo "<center>Uploaded To accountant</center> "; mysql_close(); } } $file_name = $_FILES['ufile']['name']; $random_digit=rand(0000,9999); $new_file_name=$random_digit.$file_name; $path2= "deputy_director/".$new_file_name; if($file !=none) { if(copy($_FILES['ufile']['tmp_name'], $path2)) { mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("my_database"); $strSQL = "INSERT INTO deputy_director"; $strSQL .="(date,time,Name,file,sender) VALUES ('$date','$time','".$_POST["txtName"]."','$new_file_name','".$_POST["sender"]."')"; mysql_query($strSQL); echo "<center>Uploaded To deputy_director</center> "; mysql_close(); } } $file_name = $_FILES['ufile']['name']; $random_digit=rand(0000,9999); $new_file_name=$random_digit.$file_name; $path3= "Administrative_officer/".$new_file_name; if($file !=none) { if(copy($_FILES['ufile']['tmp_name'], $path3)) { mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("my_database"); $strSQL = "INSERT INTO Administrative_officer"; $strSQL .="(date,time,Name,file,sender) VALUES ('$date','$time','".$_POST["txtName"]."','$new_file_name','".$_POST["sender"]."')"; mysql_query($strSQL); echo "<center>Uploaded To Administrative_officer</center> "; mysql_close(); } } else { echo "ERROR....."; } ?> |
<?php $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = ''; $dbName = 'my_database'; $dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); ?> <html> <head> <title></title> </head> <body> <h2><font color="#54164e"><center>Accountant</font></center></h2> <table align="center" bgcolor="#9a7608" cellpadding="10" cellspacing="3"> <tr bgcolor="#ffffff"> <th> <center> ID </center> </th> <th> <center> File Name </center> </th> <th> <center> Type </center> </th> <th> <center> Open File </center> </th> <th> <center> Delete Files </center> </th> </tr> <?php if($_POST['btsubmit']=='Submit') { foreach($_POST as $k => $v){ $$k = $v; } $dir ="accountant"; $to_del= $_POST['to_del']; if (("submit")&&($to_del != "")) { foreach($to_del as $rfn) { $remove = "$dir/$rfn"; unlink($remove); } } foreach($to_del as $v){ mysql_query("DELETE FROM accountant where file='$v'"); } echo "<center><font color='white' size=5> records is been deleted.</font></center></br>"; } ?> <?php $query = "SELECT * FROM accountant"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ ?> <form name="form" method="post"> <tr bgcolor="#ffffff"> <td><?php echo $row["ID"];?></td> <td><?php echo $row["Name"];?></td> <td><?php echo $row["file"];?></td> <td><a href="accountant/<?php echo $row['file'];?>">View</a></td> <td> <center> <input type=checkbox name="to_del[]" value="<?php echo $row["file"];?>">Yes </center> </td></tr> <?php } ?> <tr><th colspan=4 bgcolor="#ffffff">Select Check box and Press Submit To Delete files</th> <td bgcolor="#ffffff"><input type="submit" value="Submit" name="btsubmit"></td> </tr> </table> </form> </body> </html> |
Accountant page will look as below.
Accountant
1 | wintekweb | 94530802772A20120502M00201.jpg | View | |
2 | wintekweb2 | 413010 ways to make money online.docx | View | |
3 | wintekweb3 | 6057db.sql | View | |
Select Check box and Press Submit To Delete files |
By clicking the View you can see the file uploaded by director. Here by clicking check box and press submit file also could be deleted.
No comments:
Post a Comment