Page 1 of 1

Uploader Script - Max File Size

Posted: Wed Nov 22, 2006 8:53 am
by NoobieOobie
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi Guys,
I have managed to create a php file uploader and yes it works pretty sweet but thats about as far as my newly found php skills go.
I have been trying for ages to add some code to it so that i can either limit the file size a user uploads or just allow them to upload what ever size they want.

This is my form on my html page:

[syntax="html"]<form enctype="multipart/form-data" action="uploader.php" method="POST">
<table  border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
Choose a file to upload: <span class="style12">(Max file size 100Mb)</span> </td>
    <td><input name="uploadedfile" type="file" /></td>
    <td><input name="submit" type="submit" value="Upload File" /></td>
  </tr>
</table>
</form>
and this is the php file i use:[/syntax]

Code: Select all

<?php
 // Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$_FILES['uploadedfile']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    /*echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";*/
$URL="submit/submitsent.htm";
header ("Location: $URL");
} else{
   /* echo "There was an error uploading the file, please try again!";*/
$URLWRONG="submit/submitfail.htm";
header ("Location: $URLWRONG");
}
?>
Please can someone point me in the right direction as to how i can specify the file size and or type of files being uploaded.

cheers

NoobieOobie


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Nov 22, 2006 10:06 am
by pickle
Welcome to Devnet!

There are 2 places you can change the maximum uploaded file size. The first place would be in your form. Changing the value of MAX_FILE_SIZE has an affect. There is also a place in php.ini that will allow you to change the max uploaded file size. If you don't have access to your server's php.ini file, look into the ini_set() function which allows you to change ini settings.

Also, as an FYI, if you're posting PHP code, you can denote it with [syntax="php"][/syntax] tags rather than [syntax=php][/syntax] tags, to get proper syntax highlighting.

cheers

Posted: Wed Nov 22, 2006 10:08 am
by NoobieOobie
Thanks for your reply ill look into the set ini then if i cant get access

cheers again