PHP multiple File Upload

Source: Internet
Author: User
Tags file upload html page php code

This script uploads multiple files at a time. For uploading multiple files at a time, first create an upload according to the specified number of file tables. When you create a table, the files should be posted separately in each row and column. After arranging the exact location of the file, you must set it to Ufile, type equal to the file input name, id ufile equal to 50 of the size. Similarly, you must set the center alignment, input, submit type, submit and upload the value name. Close the table individually and close the form to access the data. After the development of the GUI in the HTML page, you will be using PHP code.

Let's take a look at the steps in designing the graphical user interface form:

Set standard HTML to name the DOCTYPE publicly exposed HTML code

Start with <HTML> HTML tags, start with

Name the program's name and start the program code in the body.

Determines the width, borders, alignment, and color of the table to appear on the output screen.

The form Action command is used as the starting form. Define form action equals "multiple_upload_ac.php", Method equals "after", character encoding = "Mutipart/form data", Name equals "Form1" and id = "Form1"

The table structure that is contained in the next row. Set table width to 100%, border = 0 (can be set 2 or 3 dots thick), cellpading, can hide and table colors.

Named "Multiple file upload bold letter code" title

Now select one of the files, enter the name, type, ID and file size, and call one of the plans.

For the submit button, set alignment equals center, input type equals commit, submit same name and value equals upload.

Close the table, and then close the form.

Close the body and end tag of the HTML file.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> multiple Files Upload </TITLE>
<BODY>
<table width= "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-A-file
<input name= "ufile[]" type= "file" id= "ufile[" "size=" "/></td>"
</tr>
<tr>
<td>select Second File
<input name= "ufile[]" type= "file" id= "ufile[" "size=" "/></td>"
</tr>
<tr>
<td>select Third File
<input name= "ufile[]" type= "file" id= "ufile[" "size=" "/></td>"
</tr>
<tr>
&LT;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 the HTML code for the GUI of multiple upload files in the PHP program. To do this, you must first set the path of all three files. These files can be published, but the variable $ _files command, upload file. Now, you should set the path from the copy file to the target storage space. When copying files, you must also give the temporary names of all three file types in processing work, setting file names, file sizes, files. Also give commands for printing an image file on the path and file size of the "img src" command. Now, use the command to print the file error or the success of the process. After that, the request condition statement prints the failure to upload the separate command.

See the steps:

Start the PHP tag? PHP's

The path of all three files in the first group.

Copy file from source to destination is temporary name upload

Upload a command for the printed file name, file size, file type, and image source for each file.

Displays the given command error or the success of the file.

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

<?php
Setting Path for files

$path 1= "C:\wamp\www\projects\public_html\upload_file\". $_files[' ufile ' [' name '][0];
$path 2= "C:\wamp\www\projects\public_html\upload_file\". $_files[' ufile ' [' name '][1];
$path 3= "C:\wamp\www\projects\public_html\upload_file\". $_files[' ufile ' [' name '][2];

Copy file to where the want to store file

Copy ($_files[' ufile '] [' tmp_name '][0], $path 1);
Copy ($_files[' ufile '] [' tmp_name '][1], $path 2);
Copy ($_files[' ufile '] [' tmp_name '][2], $path 3);

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 "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 "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 "


Code to display the error or success.

$filesize 1=$_files[' ufile ' [' Size '][0];
$filesize 2=$_files[' ufile ' [' Size '][1];
$filesize 3=$_files[' ufile ' [' Size '][2];

if ($filesize 1 && $filesize 2 && $filesize 3!= 0)
{
echo "<br/>";
echo "Your files have entered successfully";
}

else {
echo "ERROR ...";
}

if ($filesize 1==0) {
echo "There ' re something problem in your-a-file!";
echo "<br/>";
}

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

if ($filesize 3==0) {

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

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.