In some applications such as file attachments in Yahoo email or upload files in Cpanel server hosting,we can immediately upload multiple files at once.For that we can use arrays and loops.
Make a table in advance to accommodate the information from the uploaded file.
Then bolts unutk accommodate special folder the files that you upload.such as folders files the folder should be placed in the folder where you saved the web.
<?php
$lokasi_file = $_FILES['fupload']['tmp_name'];
$nama_file = $_FILES['fupload']['name'];
$ukuran_file = $_FILES['fupload']['size'];
echo "File-file yang berhasil diupload: <BR><BR>";
/ / Calculate the number of uploaded files
$jml_file=count($nama_file);
$i=0;
/ / Do the repetitions for $ i <= number of uploaded files
while ($i < $jml_file)
{
if ($nama_file[$i] != ""){
$direktori = "files/$nama_file[$i]";
move_uploaded_file($lokasi_file[$i],"$direktori");
echo "<B>$nama_file[$i]</B><BR>";
/ / Insert the file information into the database
mysql_connect("localhost","root","pajarmaning");
mysql_select_db("pintar");
$input="INSERT INTO upload_file(nama_file,ukuran_file,deskripsi,direktori)
VALUES('$nama_file[$i]','$ukuran_file[$i]','$_POST[deskripsi]','$direktori')";
mysql_query($input);
}
$i++;
}
?>
First of all, run the script form_uploadesfiles.php,then click the button five Browse.lalu find the file you upload, and press the upload button
Make a table in advance to accommodate the information from the uploaded file.
| Field | Type | Length | Extra | Primary |
| Id_upload | Int | 3 | Auto_increment | yes |
| Nama_file | Varchar | 100 | | |
| Ukuran | int | 100 | | |
| Deskripsi | text | | | |
| Direktori | varcahr | 100 | | |
Then bolts unutk accommodate special folder the files that you upload.such as folders files the folder should be placed in the folder where you saved the web.
Script form_uploadesfiles.php
<FORM ENCTYPE="MULTIPART/FORM-DATA" ACTION="uploadfiles.php" METHOD="POST">
File 1: <INPUT TYPE="FILE" NAME="fupload[]"><BR>
File 2: <INPUT TYPE="FILE" NAME="fupload[]"><BR>
File 3: <INPUT TYPE="FILE" NAME="fupload[]"><BR>
File 4: <INPUT TYPE="FILE" NAME="fupload[]"><BR>
File 5: <INPUT TYPE="FILE" NAME="fupload[]"><BR>
< INPUT TYPE="SUBMIT" VALUE="Upload"> </FORM>
<?php
$lokasi_file = $_FILES['fupload']['tmp_name'];
$nama_file = $_FILES['fupload']['name'];
$ukuran_file = $_FILES['fupload']['size'];
echo "File-file yang berhasil diupload: <BR><BR>";
/ / Calculate the number of uploaded files
$jml_file=count($nama_file);
$i=0;
/ / Do the repetitions for $ i <= number of uploaded files
while ($i < $jml_file)
{
if ($nama_file[$i] != ""){
$direktori = "files/$nama_file[$i]";
move_uploaded_file($lokasi_file[$i],"$direktori");
echo "<B>$nama_file[$i]</B><BR>";
/ / Insert the file information into the database
mysql_connect("localhost","root","pajarmaning");
mysql_select_db("pintar");
$input="INSERT INTO upload_file(nama_file,ukuran_file,deskripsi,direktori)
VALUES('$nama_file[$i]','$ukuran_file[$i]','$_POST[deskripsi]','$direktori')";
mysql_query($input);
}
$i++;
}
?>
First of all, run the script form_uploadesfiles.php,then click the button five Browse.lalu find the file you upload, and press the upload button

0 comments: on "Mulitple File Upload"
Post a Comment
Terima kasih atas kunjungan anda