Uploading the multiple files


 

Uploading the multiple files

Here you will learn about uploading the multiple files at a time.

Here you will learn about uploading the multiple files at a time.

Multiple File uploading

This script uploads the multiple file at a time. For uploading the multiple files at a time, first create a table as per required number of files to be uploaded. After creating a table, the files should be posted separately in every row and column. After arranging the file in the exact location, you will have to set the input name as ufile, type equal to file, id equal to ufile size equal to 50. Similar, you will have to set the alignment as center, input type as submit, name as submit and value as upload. close the table one by one and close the form from which the data have to be accessed. After developing the GUI page in HTML, you will have to use those in php code.  

Let's see the steps for designing GUI form:

Set the standard HTML public code by naming DOCTYPE HTML PUBLIC

Begin the HTML tag with <HTML>; Begin the code tag with <HEAD>; 

Name the title of the program; begin the programming code in the body.

Determine the table width, border, alignment, and color that looks on the screen in the output.

Begin the form using form action command. Define form action equal to "multiple_upload_ac.php", method equal to "post", enctype="mutipart/form-data", name equal to "form1" and id="form1"

set the table structure in the next line. Set the width of the table is 100%, border =0(it can be set 2 or 3 point thick), cellpading, cellspacing and colour of the table.

Name the title of the code in bold letters like "Multiple File Upload"

Now, select the file one by one, input the name, type, id and size of the file and call it in the program one by one. 

For the submit button, set the alignment equal to center, input type equal to submit, name equal to submit and value equal to upload. 

close the table, then close the form.

Close the HTML file body and End the Tag.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Multiple Files Upload </TITLE>
<BODY>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Multiple Files Upload </strong></td>
</tr>
<tr>
<td>Select First file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select Second file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select Third file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</BODY>
</HTML>

Now, you will have to use this HTML code of GUI in the PHP program to multiple upload the file. For this, you will have to first set the path of all the three files. The files can be posted though $_FILES command, which upload the file. now, you should copy the file from the set path to the destination storage space. During copying the file, must also give the temporary names that work during the processing, set the file name, file size, file type of all the three files. Also give the command for printing the image of the file on the screen by giving the command 'img src' with path and file size. Now, use the command to print the file error or success of the process. After that apply the conditional statement to print the command of uploading of failure separately.

See, the steps:

Begin the PHP tag <?php

First set the path of all the three files.

Copy the file from the source to destination to where to be uploaded with temporary name

Give the command of printing the file name, file size, file type and image sources of each files to be uploaded.

Display the error or success of the file by giving the command.

Use the conditional statement to print the upload or failure of each file.

End the PHP (tag ?>).

<?php
// Setting path for files

$path1= "C:\\wamp\\www\\projects\\public_html\\upload_file\\".$_FILES['ufile']['name'][0];
$path2= "C:\\wamp\\www\\projects\\public_html\\upload_file\\".$_FILES['ufile']['name'][1];
$path3= "C:\\wamp\\www\\projects\\public_html\\upload_file\\".$_FILES['ufile']['name'][2];

//copy file to where you want to store file

copy($_FILES['ufile']['tmp_name'][0], $path1);
copy($_FILES['ufile']['tmp_name'][1], $path2);
copy($_FILES['ufile']['tmp_name'][2], $path3);

echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";


//code to display the error or success.

$filesize1=$_FILES['ufile']['size'][0];
$filesize2=$_FILES['ufile']['size'][1];
$filesize3=$_FILES['ufile']['size'][2];

if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "<BR />";
echo "your files have entered successfully";
}

else {
echo "ERROR.....";
}

if($filesize1==0) {
echo "There're something problem in your first file!";
echo "<BR />";
}

if($filesize2==0) {
echo "There're something problem in your second file!";
echo "<BR />";
}

if($filesize3==0) {

echo "There're something problem in your third file!";
echo "<BR />";
}

?>

 


 

Ads