Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > All Around Tutorials > Serverside Scripting Tutorials
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-10-2007, 05:34 PM
  #1
Vege
Super Deity (Level 18)
 
Join Date: Sep 2004
Location: Finland
Posts: 3,410
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really nice
PHP File upload barebone version

File upload is regularly asked and people see it as a hard job with allot of code so i put here the minimal working code to upload something to a folder on a unix server.

This code assumes that in the same folder this script is there is a folder called "files" and that it has correct permissions so you can upload data into it (chmod 777 or similar)

Keep in mind that you allways need to check are uploading stuff you wanted meaning you need to check the file extension, content type, file size and that file is unique and and and.
Basically only these mandatory checks (that i don't present here) makes the code long.

PHP Code:
<?php
//If submit has been pressed (if it's set)
if (isset($_POST['submit'])) {
  
/* $_FILES is an array that contains information from the uploaded file. Different uploads are separated by the name variable that you set in the form (myfile in this case). In this example we use 
tmp_name thats the actual uploaded file with random name. Name here is the actual given filename in your own machine. This action just moves the tmp_name file with new name into different location in the same server */
  
move_uploaded_file($_FILES['myfile']['tmp_name'],"./files/".$_FILES['myfile']['name']);
}

/* Normal form. Only thing that might be new is the enctype which without the upload progress will not work. */

echo "<form action='{$_SERVER['PHP_SELF']}' method='post' enctype='multipart/form-data'>";
echo 
"<input type='file' name='myfile' value='' />";
echo 
"<input type='submit' name='submit' value='Submit' />";
?>

Last edited by Vege : 06-11-2008 at 05:38 PM.
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 12-14-2007, 03:41 PM
  #2
erisco
Catapulted
 
erisco's Avatar
 
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,858
iTrader: (0)
erisco will become famous soon enougherisco will become famous soon enough
There is additionally a lot of information and barebone/advanced examples on http://php.net/features.file-upload
erisco is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 04:15 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.