Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2007, 12:24 PM   PM User | #1
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
Uploader for newbie coders. Commented.

Hey people, thought this might be useful. Its a veeeery easy way to upload things.
The php

PHP Code:
<?php

$max_size 
15//Your maximum file size(in mb);
$direc_copy "uploads/"//Directory to copy to
//Seperate with a comma
$accepted_file_list "video,image"// the files types you will allow to be copied, Possible options are:
//text,image,audio,video,application

$accepted_file_list explode(",",$accepted_file_list);
$max_size = (($max_size 1024) * 1024);
$submit $_POST['submit']; // get the submit
if (isset($submit)){
       
$filename $_FILES['file_upload']; //get the file details
    
$mime_type explode("/"$filename['type']); //get the first bit of the mime type
     
if (($filename['size'] > 0) and ($filename['size'] < $max_size)){ //check if a file actually exists.
        
if (in_array($mime_type[0], $accepted_file_list)){//check if the file is in the accepted_file_list array
            
copy($filename['tmp_name'], $direc_copy $filename['name']); // copy the file
            
$message "Your file has been uploaded."//message if copied
            

            else {
                
$message "Filetype not supported"//message if filetype not supported
                
}
        } else {
            
$message "File is outside of the allowed boundaries";
            }
}
?>
<form action="uploader_test.php" method="post" enctype="multipart/form-data" name="fileuploader" id="fileuploader">
<input type="file" name="file_upload" id="file_upload">
<input type="submit" name="submit" value="submit">
</form>
PHP Code:
<?php echo($message "<br>" "The link is " $direc_copy $filename['name']); ?>
idalatob is offline   Reply With Quote
Users who have thanked idalatob for this post:
Bhodio (09-14-2007)
Old 09-14-2007, 04:00 AM   PM User | #2
Bhodio
New to the CF scene

 
Join Date: Sep 2007
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Bhodio is an unknown quantity at this point
thats a nice simple script
Bhodio is offline   Reply With Quote
Old 12-02-2007, 06:44 AM   PM User | #3
afe
Banned

 
Join Date: Sep 2007
Posts: 146
Thanks: 43
Thanked 0 Times in 0 Posts
afe is an unknown quantity at this point
Hey, I published a page for the uploader. http://www.athletes4excellence.com/uploader.php how come it takes me to a broken page after uploading?
afe is offline   Reply With Quote
Old 12-02-2007, 07:53 AM   PM User | #4
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
Quote:
Originally Posted by afe View Post
Hey, I published a page for the uploader. http://www.athletes4excellence.com/uploader.php how come it takes me to a broken page after uploading?
the script is supposed to be put in a file called uploader_test.php u've put it in uploader.php but haven't changed the form-action

Code:
<form action="uploader.php" method="post" enctype="multipart/form-data" name="fileuploader" id="fileuploader">
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Old 12-02-2007, 07:39 PM   PM User | #5
afe
Banned

 
Join Date: Sep 2007
Posts: 146
Thanks: 43
Thanked 0 Times in 0 Posts
afe is an unknown quantity at this point
Ohh I see.
thanks

However, this is what I get now after clicking "Submit"

"Warning: copy(uploads/1J4V6SCAF8V6FVCAAHPYS1CA38NA1KCAOEJJIQCA3OQUQVCA601F3ZCAE8MUBYCAC2KLK8CAHVUAECCAS0I322CAMAMTOBCA116R EPCAG7HN5CCACXACTOCA48F6VMCAF6A91UCAH7DNLGCATV3O53CACDBHIS.jpg) [function.copy]: failed to open stream: No such file or directory in /home/athletes/public_html/uploader.php on line 17"

Last edited by afe; 12-02-2007 at 07:42 PM..
afe is offline   Reply With Quote
Old 12-03-2007, 05:49 AM   PM User | #6
fl00d
Regular Coder

 
Join Date: Mar 2007
Location: Quebec
Posts: 261
Thanks: 6
Thanked 7 Times in 7 Posts
fl00d has a little shameless behaviour in the past
create a folder called uploads
fl00d is offline   Reply With Quote
Old 12-03-2007, 12:24 PM   PM User | #7
ahallicks
Senior Coder

 
ahallicks's Avatar
 
Join Date: May 2006
Location: Lancaster, UK
Posts: 1,134
Thanks: 1
Thanked 57 Times in 55 Posts
ahallicks is on a distinguished road
Or, to be more specific (and the only way to get it to work on my server) change the upload path to:

PHP Code:
$direc_copy "/home/athletes/public_html/uploads/" //Directory to copy to 
and create a folder called 'uploads' in the public_html folder of your server
__________________
"write it for FireFox then hack it for IE."
Quote:
Originally Posted by Mhtml View Post
Domains are like women - all the good ones are taken unless you want one from some foreign country.
Reputation is your friend

Development & SEO Tools

Last edited by ahallicks; 12-03-2007 at 12:28 PM..
ahallicks is offline   Reply With Quote
Old 03-14-2011, 11:11 AM   PM User | #8
MattClark
Regular Coder

 
Join Date: Jan 2011
Posts: 120
Thanks: 6
Thanked 2 Times in 2 Posts
MattClark has a little shameless behaviour in the past
it's telling me the file is too large?...and i'm uploading a 26 kb pic.. does anyone know why?
MattClark is offline   Reply With Quote
Old 03-13-2012, 06:51 PM   PM User | #9
p@p
New Coder

 
Join Date: Apr 2010
Location: Indonesia
Posts: 71
Thanks: 4
Thanked 0 Times in 0 Posts
p@p has a little shameless behaviour in the past
Quote:
Originally Posted by MattClark View Post
it's telling me the file is too large?...and i'm uploading a 26 kb pic.. does anyone know why?
Did you already check the php.ini for maximum_uploads values?
p@p is offline   Reply With Quote
Old 05-11-2012, 12:22 PM   PM User | #10
Nikey646
New Coder

 
Join Date: May 2012
Posts: 31
Thanks: 0
Thanked 7 Times in 7 Posts
Nikey646 is an unknown quantity at this point
Doesnt this essentially use a slightly modified version of the $_POST['submit'] bug as listed by TangoForce?

if so a fix would be to change $submit to

PHP Code:
 $submit $_POST['upload']; // get the submit 
and add

Code:
<input type="hidden" name="upload" />
Nikey646 is offline   Reply With Quote
Users who have thanked Nikey646 for this post:
WolfShade (05-11-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:07 AM.


Advertisement
Log in to turn off these ads.