Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Recent Updates
[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » PHP
 Simple Upload Page
Pages: [1]   Go Down
  Print  
Author Topic: Simple Upload Page  (Read 4008 times)
Daniel Franklin
TWI Hero
**********


Karma: 3
Offline Offline

Posts: 16647


View Profile Email
Simple Upload Page
« Posted: September 26, 2007, 01:27:08 PM »


ith this code, you can create an upload page that combines HTML and PHP easily. this Source code has been writen form T4VN Team. so, if you want to develop it, please contact us. Thanks for your interested in this code

Step 1: Create one page with HTML content






Upload


File:






Step 2 : Create file upload.php with content :
// $userfile is where file went on webserver
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];
// $userfile_name is original file name
$userfile_name = $HTTP_POST_FILES['userfile']['name'];
// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['userfile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $HTTP_POST_FILES['userfile']['type'];
// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['userfile']['error'];

// userfile_error was introduced at PHP 4.2.0
// use this code with newer versions

if ($userfile_error > 0) {
echo 'Problem: ';
switch ($userfile_error)
{ case 1:
echo 'File exceeded upload_max_filesize';
break;
case 2:
echo 'File exceeded max_file_size';
break;
case 3:
echo 'File only partially uploaded';
break;
case 4:
echo 'No file uploaded';
break;
}
exit;
}

// put the file where we'd like it
$upfile = '/uploads/'.$userfile_name;

// is_uploaded_file and move_uploaded_file
if (is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
} else {
echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
exit;
}
echo 'File uploaded successfully

';

// show what was uploaded
echo 'Preview of uploaded file contents:
';
echo $contents;
echo '
';
?>

Note :line: $upfile = '/uploads/'.$userfile_name; Folder of files have been stored, you can change it depending on your ideas

Another form of Upload file, you can choose file that you want to upload optionally

Create file upload.php with contents :

//Define some variables
$dir = "path/where/you/want/to/upload/files/"; //Bạn nên thay ðổi ðýờng dẫn cho phù hợp
//Kiều file, Gif, jpeg, zip ::bạn có thể sửa ðổi nếu thích
$types = array("image/gif","image/pjpeg","application/x-zip-compressed");

//Check to determine if the submit button has been pressed
if(isset($_POST['submit'])){

//Shorten Variables
$tmp_name = $_FILES['upload']['tmp_name'];
$new_name = $_FILES['upload']['name'];

//Check MIME Type
if (in_array($_FILES['upload']['type'], $types)){

//Move file from tmp dir to new location

move_uploaded_file($tmp_name,$dir . $new_name);

echo "{$_FILES['upload']['name']} was uploaded sucessfully!";

}else{

//Print Error Message

echo "File {$_FILES['upload']['name']} Was Not Uploaded!
";

//Debug
$name = $_FILES['upload']['name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$tmp = $_FILES['upload']['name'];

echo "Name: $name
Type: $type
Size: $size
Tmp: $tmp";

}

}

else{

echo 'Could Not Upload Files';

}
?>




Upload Files






You are done.Good luck

About Author :
T4VN.NET is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support,coupon code for hosting,download free template.
Visit : http://www.t4vn.net you can get more information with PHP Code,PHP Example,Download free script,...

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.12 seconds with 24 queries.