Important alert: (current site time 7/15/2013 10:26:09 AM EDT)
 

VB icon

Another way to Upload

Email
Submitted on: 3/3/2001 11:11:54 AM
By: Steve Oliver 
Level: Beginner
User Rating: By 11 Users
Compatibility: PHP 4.0
Views: 56138
(About the author)
 
     Uploads up to 5 files user PHP, works perfectly on win32 servers such as IIS or Apache for windows. Demonstrates the use of copy(), functions, and switch operators.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Another way to Upload
// Description:Uploads up to 5 files user PHP, works perfectly on win32 servers such as IIS or Apache for windows. Demonstrates the use of copy(), functions, and switch operators.
// By: Steve Oliver
//
// Inputs:$destination should be set to where you want the files uploaded to.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=285&lngWId=8//for details.//**************************************

<?
function uploadProg($filename1,$filename1_name,$filename2,$filename2_name,$filename3,$filename3_name,$filename4,$filename4_name,$filename5,$filename5_name){
########Set the destination here##############
$destination="C:\\Uploads\\";
copy($filename1,$destination."/".$filename1_name);
copy($filename2,$destination."/".$filename2_name);
copy($filename3,$destination."/".$filename3_name);
copy($filename4,$destination."/".$filename4_name);
copy($filename5,$destination."/".$filename5_name);
echo "<h1>File(s) Uploaded...</h1>";
echo "<b>$filename1_name was uploaded succesfully.</b><br>";
echo "<b>$filename2_name was uploaded succesfully.</b><br>";
echo "<b>$filename3_name was uploaded succesfully.</b><br>";
echo "<b>$filename4_name was uploaded succesfully.</b><br>";
echo "<b>$filename5_name was uploaded succesfully.</b><br><br>";
echo "<a href=\"upload.php\">Click here to go back.</a>";
}
function main(){?>
<form method="post" action="upload.php" enctype="multipart/form-data">
Files to Upload:<br>
<input type="file" name="filename1" size="20" tabindex="1"><br>
<input type="file" name="filename2" size="20" tabindex="2"><br>
<input type="file" name="filename3" size="20" tabindex="3"><br>
<input type="file" name="filename4" size="20" tabindex="4"><br>
<input type="file" name="filename5" size="20" tabindex="5"><br>
<input type="hidden" name="action" value="uploadProg">
<input type="submit" value="Upload Files" tabindex="6">
</form><?}
switch ($action){
default:
main();
break;
case "uploadProg":
if ($filename1=="none") {echo("<h1>No File Selected....</h1>"); break;}
uploadProg($filename1,$filename1_name,$filename2,$filename2_name,$filename3,$filename3_name,$filename4,$filename4_name,$filename5,$filename5_name);
break;
}
?>


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

6/27/2001 2:19:47 PMPhil Essing

Thanks for the code, Steve! It was very easy to customize and implement. I have one question, though: will this upload module work with any file extention and size? I ask this because the process always fails with large (2 meg, for example) files.

Thanks again!

-phil
(If this comment was disrespectful, please report it.)

 
7/15/2001 6:11:11 PMDavid Overcash

if the code fails to upload somthing, and it tends to show up with larger size files that could either be a setting by the server or there is not enough allocated memory on the server to complete a copy task of that size...
(If this comment was disrespectful, please report it.)

 
10/9/2001 5:02:25 PMcaciola@estado.com.br

Hi,

I'm having one Warning message, please see above.

Warning: Undefined variable: action in C:\WebMaster3\Script\PHP\Another way to Upload.php on line 47

What do I do to fix this message ?


Thank's
(If this comment was disrespectful, please report it.)

 
4/25/2002 7:40:07 PMMoumen

where can i paste this script please someone help me. please

i need to let users upload for me mp3s and download i have a server 24 hours daily open with 120 gigabyte.
(If this comment was disrespectful, please report it.)

 
7/11/2002 12:54:55 PMchris

i'm very new in php. So, I need to save this copy-and-paste code wherever is the name of file, isn't it? And how about the upload.php file in the form?
help me. just a beginner. tYou

(If this comment was disrespectful, please report it.)

 
7/26/2002 2:46:28 PMJeffrey Cook

I downloaded your "Another way to Upload" code and I can't get it to work. Should I have to install another module that works with your code? I get errors pertaining to undefined variables that you use in the form. The PHP code is not seeing those variables at all. Can you assist me please?
(If this comment was disrespectful, please report it.)

 
8/8/2002 10:17:26 AMkaiserm22@yahoo.com

Hi, I like u code it vvery nice and straight forward.
I am kinda new to php coudl u show me an example how i can upload file to through http to a remote server for example http.mydomain.com/tmp/.

thank a lot
my email kaiserm22@yahoo.com
(If this comment was disrespectful, please report it.)

 
9/15/2002 12:15:07 PM$t0rm

who hosts on win32...i know i dont
(If this comment was disrespectful, please report it.)

 
9/22/2002 5:55:42 AMHell_Freezer

brialliant, i give it 5 globes, with a little bit of config i got it working, complete with file browser, at the following url:
http://www.clanef.co.uk/brownies/upload/upload.php
(If this comment was disrespectful, please report it.)

 
12/2/2002 5:43:13 PM

I too am having troubles with an
(If this comment was disrespectful, please report it.)

 
12/2/2002 7:56:01 PM

I am having troubles with the :Undefined Variable: 'action'
(If this comment was disrespectful, please report it.)

 
12/8/2002 2:59:24 PMAlex Wied (PcExpert)

Parse error: parse error in /home/vhost/pcexpert/php/upload.php on line 39
(If this comment was disrespectful, please report it.)

 
1/5/2003 11:23:43 PMmaxs hate jologs

Cool! It so easy to use!! Thanks!
(If this comment was disrespectful, please report it.)

 
5/9/2003 11:29:53 AMGOD

if you are getting the error:

(If this comment was disrespectful, please report it.)

 
5/9/2003 11:31:29 AMGOD

To get rid of your undefined variable error add this piece of code just below the opening php tag "
if (isset($action) <> 1) {
$action = "";
}

Hope this helps :D
(If this comment was disrespectful, please report it.)

 
5/9/2003 11:33:30 AMGOD

okay it added line breaks :( ill try again

if (isset($action) <> 1) {
$action = "";
}

(If this comment was disrespectful, please report it.)

 
5/15/2003 10:17:42 PM

i have pasted into an html page in the body. Assumed this was the way to use. I get errors and it seems some of the code is broken. Is this the proper way to incorporate this?
(If this comment was disrespectful, please report it.)

 
6/23/2003 2:44:34 PM

How to use this code:
1.) Your website host must support PHP!
2.) Open Notepad.exe or another similar program and paste in the above code.
3.) Change the line: $destination="C:\\Uploads\\";
to
$destination="foldername";
This foldername will be where the files end up on the server. Leave it blank to upload to the root directory.
4.) Save it as: "upload.php" (with the quotes so that it will save as a .php extension.
5.) Upload the file to the root directory of your server.
6.) The address will be: http://www.yourserver.com/upload.php

Hope this clears some things up for you guys.
(If this comment was disrespectful, please report it.)

 
7/16/2003 2:04:01 PMPatrick Weber


Parse error: parse error, unexpected '>' in C:\Program Files\Apache Group\Apache2\htdocs\member\upload\index.php on line 10
(If this comment was disrespectful, please report it.)

 
8/18/2003 5:45:54 AM

HI its grat code but it doesnt work for me. If I want to upload file bigger than 500 KB then the page is reloaded and I get the information the page cannot be found. When I want to upload smaller file its OK. in php ini I set max_upload_filesize to 20M. What other setting do I have to change. It all works on RH Linux 9
(If this comment was disrespectful, please report it.)

 
12/2/2003 10:13:10 AMPhiber-OptiX

doesn't werk 4 me either....
(If this comment was disrespectful, please report it.)

 
12/10/2003 6:52:11 AMManas Mukherjee

hmm ! he is a winner.
(If this comment was disrespectful, please report it.)

 
9/3/2004 11:13:24 AM

WHOOAAAA GREAT WORK DUDE!!!!
(If this comment was disrespectful, please report it.)

 
11/9/2004 12:32:02 PM

That WAS TOO Easy!! Once I got the destination correct in the script, it worked perfectly. You don't know how much time you just saved me trying to teach clients to use FTP or their CPanel!?!?
I did a Google search for upload PHP, and there was your link! First link I clicked on...~~!
Thanks AGAIN Steve!!!!

(If this comment was disrespectful, please report it.)

 
2/17/2005 2:09:22 PM

Great SIMPLY written code. How to I make it a cronjob php by automatically sending a file from my PC. I don't mind editing the filename. The ability to make it run in the early morning is a great PLUS. THANKS.
(If this comment was disrespectful, please report it.)

 
4/12/2005 6:44:21 PMdan b.

good code, but where is upload.php? without that file the code is useless.
(If this comment was disrespectful, please report it.)

 
4/23/2005 6:50:31 PMLawrence Wagerfield

This aint working for me, I even followed those simple steps that that guy posted, the page is displayed, when I select a file and hit the UPLOAD button, the page is refreshed, and nothing has been uploaded
(If this comment was disrespectful, please report it.)

 
5/19/2005 7:21:54 PM

Yeah, i am having the same problem. when i click upload, it just refreshes and clears the selected uploads
(If this comment was disrespectful, please report it.)

 
8/3/2005 11:26:04 AMMan w Shiny Button

Hey little dudes, don't do it, it's a trap. Lol, nah just kidding it's an honest try at a buggy code. OK kiddo, first things first, yes infact that was waaay too easy. If someones say, uploads "script.php" and then goes to it, he can parse w/e code he wants. Next up, if the person say, uploads "/etc/passwd" he'll take a protected file (that has the passwords), and then makes a copy that isn't in a protected directory and all he has to do is crack your password, and he's free to do whatever he wants once again. So buyer beware, make sure before you implement that code, add a feature to check if the has a certain extension (for example ban all asp, php,etc files that are server side scripts)and finally check to make sure that the file your are copying is a file that is uploaded, not one that is already in your server (using the is_uploaded_file function). Laterz
(If this comment was disrespectful, please report it.)

 
5/5/2006 9:14:02 PMMoThErHaCkErMxLi

how to validate files only .zip or .rar !?
(If this comment was disrespectful, please report it.)

 
2/2/2007 1:24:34 AMvanilla_rice

wow, cool. this is the first php thing ive done with my site and it works flawlessly after a few tweaks... i changed "upload.php" to "index.php" and put it in its own subfolder, and had the images upload to another supfolder of that one.

yahoo webhosting only recently gave me php so this is really cool for me.
(If this comment was disrespectful, please report it.)

 
11/6/2008 8:15:02 PMAndron Smith

move_uploaded_file is better, even though the file is automatically deleted after the script is done you'd want to make sure it stays removed.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.