...

Uploader for newbie coders. Commented.

idalatob
09-05-2007, 12:24 PM
Hey people, thought this might be useful. Its a veeeery easy way to upload things.
The php

<?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 echo($message . "<br>" . "The link is " . $direc_copy . $filename['name']); ?>

Bhodio
09-14-2007, 04:00 AM
thats a nice simple script

afe
12-02-2007, 06:44 AM
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?

shyam
12-02-2007, 07:53 AM
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

<form action="uploader.php" method="post" enctype="multipart/form-data" name="fileuploader" id="fileuploader">

afe
12-02-2007, 07:39 PM
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"

fl00d
12-03-2007, 05:49 AM
create a folder called uploads

ahallicks
12-03-2007, 12:24 PM
Or, to be more specific (and the only way to get it to work on my server) change the upload path to:

$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

MattClark
03-14-2011, 11:11 AM
it's telling me the file is too large?...and i'm uploading a 26 kb pic.. does anyone know why?

p@p
03-13-2012, 06:51 PM
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?

Nikey646
05-11-2012, 12:22 PM
Doesnt this essentially use a slightly modified version of the $_POST['submit'] (http://www.codingforums.com/showthread.php?t=240088) bug as listed by TangoForce (http://www.codingforums.com/member.php?u=113086)?

if so a fix would be to change $submit to

$submit = $_POST['upload']; // get the submit and add


<input type="hidden" name="upload" />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum