Applied I's Script MySimpleFileUploader you can download it from here, but with more additions of annotated here


We will explain today's programming simple files upload center with a beautiful and safe properties


Setup:
In this step we'll create and organize folders that we will need ...
First Log in to your server or personal site ... And then create a new folder named upload, and create the following folders inside:
- Uploaded.
- Includes.
- Style.
Inside the folder includes create a folder named cache.
Inside the folder style create a folder named template.

System templates:

We'll using templates mild system to be a script that we want to do more organized and usable ...
We will use the system templates MOFTemplate Engine you can visit the site and learn about it more ...
*Download the templates from the system here
(Unfortunately, I could not download the file, so you using an earlier version of the system 1.4.0.1
**And those who could not download from the official site in here last link).
After downloading the templates Loosen system pressure him, we will need to file moftemplate-engine.php,
Copy the file moftemplate-engine.php and place it inside the folder includes that we have created earlier.
We finished the installation of the system templates

Write a definition file system templates (mof-define.php) :

In this step we will no profile templates system,
Make new file named mof_define.php, inside the folder includes, and this will be its content: -

PHP Code:
<? 
  
include 'moftemplate-engine.php';  
  
$tpl        =    new moftemplate;  
  
$tpl->tempdir    =    'style/template'
  
$tpl->cachedir    =    'includes/cache'

?>
In the first line we have included a file system templates.
In the second line we turn on the system.
In the third line we have to select a folder templates.
In the fourth line we have identified a temporary files folder.

Write a settings file (config.php) :

Now we'll have left settings file and location information, which will install the script, all variables and I do not think he needs to explain:

PHP Code:
<?
# The name of the site
sitename "Advanced";

# Letter appearing in the Home
msg "Please do not use the center as angers Allah and His Messenger";


/ * 
Type in the link here with a script like folder www.name.com upload
Without http
://
*Without Last * /
site_url "localhost / upload";



# Keywords keywords that will appear as the page
meta_open "center Filan files upload";

# Song Description meta description
meta_desc "center files upload, UPLOAD, lifting, files";


/ / 
Allowable size in bytes
/ / This size is equal to 150 kilobytes (KB)
maxsize "153600";

/ / 
Allowed Extensions
alemtdadat = array ('. gif''. jpg''. jpeg''. zip''. rar''. png''. swf''. psd''. txt''. bmp');
?>
This is the file, of course, all variables and does not need to explain ... However, in the last line we have developed a matrix containing extensions ...
Now we finished the config.php file and we'll cum inside the folder includes,
Now completed the folder includes all files!


An idea of ​​the organization of working files:

We will organize our work to the greatest extent possible, so we will put the content contains the top of each page and a file containing the bottom of each page content too!
In other words we are going a file named content_up.php job and it put all what we want to be in the first file, and we will put it:
Definition file templates, include settings config.php file, summon header, and some other codes ...
And another file named content_down.php the call and we will put it to Wouter ...
Meaning it is this system, Home will only be only a few lines!
If you do not understand the significance of this, Vstfhmh later.
The printing method
Templates are system variables {variable} only.

Write the file content_up.php:

PHP Code:
<? 
 
include('includes/config.php'); 
 include(
'includes/mof_define.php'); 
  
 echo 
$tpl->show('header.htm'); 

?>
In the first line we have included the settings config.php file.
Also in the second line we have included a profile system templates.
In the third line we place an order to show template header which Snncoh later.

Write the file index.php:

Index.php file and its content:
*

PHP Code:
<?
*include ('content_up.php');

*$ 
Max_size = ($ maxsize/1024);
*$ 
Allowed_file_types implode (",", $ alemtdadat);
*$ 
Upload_path 'uploaded';

*echo $ 
tpl-> show ('upload.htm');
**
*echo $ 
tpl-> show ('footer.htm');
?>
The first line we have included file content_up.php which we have written previously ...
The second line we have dividing the maximum size allowed in 1024 in order to get the size in kilobytes to introducing the visitor.
The third line we using the function implode with arrays are used to put their content in a variable and the ability to print easily, you can search for the location of php.net.
The fourth line we have identified Upload folder path, which is uploaded folder that we have created previously.
The fifth line we have request mold upload.htm and the Snncih later.
Sixth line we have applied the template footer ...


Now we will make a three header templates, upload, footer and then we will make a file uploaded upload.php later ...
Regarding the templates and design, we will work very ordinary script design, not professionally, and you can modify it later on as you want .
If you not know HTML or CSS فأنصحك بتعلمها of their importance at this time, will not be independent of means for learning any program it was!.

*

Template header.htm:

HTML Code:
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<meta http-equiv="Content-Language" content="ar-sa">
<meta name="keywords" content="{meta_open}">
<meta name="description" content="{meta_desc}">
<title> {sitename} </ title>
</ Head>
<body style="margin:0">
<div align="center">

<table style="border:1px dotted #C0C0C0;width:100%">
<tr>
<td style="background-color:#FFFFDB;padding: 0;height:50px">
<p align="center" style="color:maroon;font-size:15pt;font-family:Tahoma">
{Sitename} </ td>
</ Tr>
<tr>
<td style="background-color:#808080;color:white;border:0px">
<p align="center">
<b>
<a href="index.php">

<a href="http://phpx3.com"> <span style="color:white;font-size:10pt;font-family:Tahoma;text-decoration: none">
Another link </ span> </ a> </ b> </ td>
</ Tr>
</ Table>

</ Div>
سأشرحه explanation lightly ..
-. In the first line we started marking the HTML and identified that the page orientation from right to left
dir = mean trend direction, and rtl meaning of right to left right to left.
- The second line started marking HEAD is usually placed in which BB JavaScript and title of the page and CSS codes often, and Mayoda the here does not appear on the page.
- The third and fourth line we have identified language and coding.
- The fifth and sixth line, we have identified keywords and words of description, and here we put {meta_open} and {meta_desc}
*Variables will deal with templates system, which we set variables in config.php.
- The seventh line we set the title of the page, which is the name of the site, which we have set sitename variable in config.php.
- The line marking the eighth closed the HEAD.
- The line marking the ninth started with body and مايقع under this tag is the content of our page.
- The rest of the lines and put two tables table where the name of the site {sitename} and another table that contains the links.
We finished template header.

*

Template footer.htm:

Below will appear on all pages, template:
*

HTML Code:
<br>
<div align="center">
<span style="font-family:Tahoma;font-size:8pt;color:teal">
All rights reserved  {sitename}
</ Span>
</ Div>
</ Body> </ html>
We have developed a new line and then center the content, and then we wrote All rights reserved sitename ...
And closed the tags that we have started with a template header.

*

Template upload.htm:

This template is a template responsible for the upload form, any lifting Fund .... Template:
*

HTML Code:
<div align="center">
<BR>
<table width="760" cellspacing="1" style="border:1px dotted #C0C0C0">
<tr>
<td style="background:gray;color:white;height:24px;text-align:center">
<font face="Tahoma" style="font-size: 10pt; font-weight:700" color="#FFFFFF"> {sitename} </ font> </ td>
</ Tr>
<tr>
<td style="background:silver;padding-top:2px;padding-bottom:2px;height:19px;text-align:center;">
<font face="Tahoma" style="font-size: 9pt; font-weight: 700"> {msg} </ font> </ td>
</ Tr>
<tr>
<td>
<table border="1" width="100%" cellpadding="0" style="border-collapse: collapse" bordercolor="#CCCCCC">
<tr>
<td width="50%" bgcolor="#ECE9D8"> <font face="Tahoma" style="font-size: 9pt">

<font color="#FF0000"> {max_size} </ font> <span lang="ar-sa"> KB
. </ Span> </ font> </ td>
<td bgcolor="#ECE9D8" width="50%">
<font face="Tahoma" style="font-size: 9pt">
the <span lang="ar-sa"> extensions allowed: <br> the
</ Span> </ font> <font color="#FF0000" style="font-size: 8pt" face="Tahoma"> {allowed_file_types} </ font> <font face = "Tahoma" style = " font-size: 9pt ">
. </ Font> </ td>
</ Tr>
</ Table>
</ Td>
</ Tr>
</ Table>
<form action="upload.php" method="post" enctype="multipart/form-data" name="form1" id="fileup">
<Table width = "760" border = "1" cellpadding = "3" cellspacing = "1" bgcolor = "# FFFFFF" bordercolor = "# C0C0C0" style = "border: 1px dotted # C0C0C0; border-collapse: collapse" id = "table5">
<tr>
<th bgcolor="#80A5E7">
<font face="Tahoma" style="font-size: 9pt" color="#FFFFFF">

</ Tr>
<tr>
<td>
<p align="center"> <font face="Tahoma">
<b>

</ B>
<Input name = "fileup" type = "file" id = "fileup0" size = "50" style = "text-decoration: underline; font-family: Tahoma; font-size: 9pt; border: 1px groove # C0C0C0; padding: 2px; font-weight: 700; cursor: hand "> </ span> </ font> </ td> </ tr> <tr>
<td align="center" bgcolor="#ECE9D8">
<font face="Tahoma"> <span style="font-size: 9pt">
: baseline; border: 1px dotted # C0C0C0; padding: 4px; background-color: # 81A7E8; font-weight: 700; cursor: hand "> </ span>
</ Font>
</ Td>
</ Tr>
</ Table>
<BR>
Of course, all the HTML tags, you do not need to explain, only we have using variables كتبناها in the index.php file to determine the maximum size for download kilobytes Alamtdadt the allowable ...

*


Upload.php responsible for files:

This is Almsawol file the file Ahouda and lift it, this is the file with the explanation inside: -
*

PHP Code:
<?
*/ / We include the upper content file
*include ('content_up.php');
*/ / 
We set the folder in which we will be lifted up to him
*$ Upload_path 'uploaded';



*/ / 
We bring the file to be lifted and his name,
*/ / 
To read more about the matrix _FILES
*/ / You can access the php.net
*$ File_name = $ _FILES ['fileup'] ['name'];
*$ 
Fileup = $ _FILES ['fileup'] ['tmp_name'];

*/ / 
We produce a random number in order to add it to the file name in order not to repeat the names of the files in a
*/ / Folder Lift
*$ Rand rand (000,999);
*/ / 
We put a variable contains the name of the file and note we have added random variable file name
*$ New_file_name = $ rand'_'. $ File_name;




*/ / If 
the file is not selected
*if ($ fileup =='') {
***
***echo $ 
tpl-> show ('upload.htm');
***echo $ 
tpl-> show ('footer.htm');
***exit;
*} Else {

**/ / 
We get file extension
**$ Att strtolower (strrchr ($ file_name'.'));

***/ / 
Fetch the file size by the function
**/ / 
Filesize
**/ / Note that this function attend the file size in bytes
**$ File_size filesize ($ fileup);

**/ / 
Make sure that the extension is in the matrix extensions
**if (! in_array ($ att, $ alemtdadat)) {
****
****echo $ 
tpl-> show ("upload.htm");
****echo $ 
tpl-> show ('footer.htm');
****exit;
*}

***/ / 
Make sure the file size
**elseif ($ file_size> $ maxsize)
**{
***/ / 
We bring the file size in kilobytes order for us to print visitor
***$ Max_size = ($ maxsize/1024);
***
***echo $ 
tpl-> show ("upload.htm");
***exit;

**} Else {
*/ / 
We have developed a variable contains the folder path and then lifting the file name in order to determine the full path
*$ Path = $ upload_path'/'. $ New_file_name;

**/ / 
Push file
**/ / Here we used the function move_uploaded_file
**/ / This function Baramtaran the
*/ / The first filethe file path and the second has been identified at the top
**$ Upload move_uploaded_file ($ fileup, $ path);

***/ / If 
the file has been lifted
***if ($ Upload)
****{
**********/ / 
Keep matrix to &#1573;متدادت images
*********/ / So if the uploaded file picturewe check the display and inclined to ICON file harmful!
*********$ 
Images = array (". Jpg"". Jpeg"". Gif"". Png"". Bmp");

****/ / If 
the extension is in the stretch matrix images
***************if (in_array ($ att, $ images))
****{
***********************/ / If 
the image Stretch n??? ?????? ???????? ??? ???? ??????? ?? ?????
**********************/ / 
Mime type "
*********************/ / By the function getimagesize
*******************/ / On Maazn that this function requires GD library
*****************/ / Also note that we have put the @ sign
***************/ / And place it means not show errors when they occur
****$ Image = @ getimagesize ($ path);


****************/ / If the image is real
****if (! stristr ($ image ['mime'], 'image'))
****{
*****************/ / We delete the file
****$ Delete = @ unlink ($ path);
****if ($ delete)
****{
****
****echo $ tpl-> show ("
upload.htm");
****echo $ tpl-> show ('footer.htm');
****exit;
****************}
*********}
****}
****/ / If the file has been raised successfully
****************/ / We get the size of the file
*****************$ Size = ($ _FILES ['fileup'] ['size'] / 1024);
****************/ / We get the file type
*****************$ Type = $ _FILES ['fileup'] ['type'];
*****************/ / Normalize the mold responsible for the information uploaded file
*****echo $ tpl-> show ("
file-was-upload.htm");
*****************echo $ tpl-> show ('footer.htm');

****} Else {
******/ / If the file is not lifted
****
****echo $ tpl-> show ("
upload.htm");
****echo $ tpl-> show ('footer.htm');

**************}

*******}
**}

?>
*

Template file-was-upload.htm responsible for submission of the result after he was taken:

HTML Code:
<div align="center">
<table style="border:1px dotted silver;width:600px" id="table1"> <tr>
<td style="text-align:center;font-size:10pt;font-family:Tahoma;background:black;color:white">
The file was downloaded successfully, Download Link: <br>
<a href="http://{site_url}/{path}" style="color:white;text-decoration:none"> http:// {site_url} / {path} </ a> </ td> </ tr>
<tr> <td style="font-family:Tahoma;color:silver;font-size:9pt;text-align:center">
File size: <b> {size} </ b> KB. <BR/>
File Type: <b> {type}. </ B> <BR/>
</ Td> </ tr>
<tr>
<TD Align="center" bgcolor="#ECE9D8" height="19">
<font color="#808080" style="font-size: 9pt" face="Tahoma">
Multiple uses: </ font> </ td>
</ Tr> <tr>

</ Font>
*<input size='100' value=' [url=http://{site_url}][img]http://{site_url}/{path} [/img][/url]' name="T3"> <font size="2">
<br /> </ font> </ font> </ td>
</ Tr>
<tr>

</ Font>
*
</ Font> </ font>

</ Td>
</ Tr>
<tr> <td style="font-family:Tahoma;background:silver" align="center"> <font face="Tahoma" size="2">
<b> page HTML: </ b> </ font> </ td> </ tr>

<br /> <tr> <td class='thead' align="center"> <font face="Tahoma"> <font size="2"> for use
As a picture in a page <span lang="en-us"> HTML </ span>: </ font>
*<Input size = '100 'value =' <a href="http://{site_url}" target="_blank"> <img src="http://{site_url}/{path}"> </ a > 'name = "T1"> <font size="2">
<br /> </ font> </ font> </ td> </ tr> <tr> <td class='thead' align="center">
<font face="Tahoma"> <font size="2"> for use as a link on the page
<span lang="en-us"> HTML </ span>: </ font>
*size = "2">
</ Font> </ font>

</ Td> </ tr> <tr> <td class="tcat" align="center"> <form method="POST" action="index.php">

</ Table>
</ Div>
*

*

We finished!
I hope that the explanation was clear