PDA

View Full Version : upload script



hungrylilboy
08-15-2006, 07:18 PM
..

tesco
08-15-2006, 08:07 PM
You only need the folder chmodded on a linux server, it just works on a windows one afaik.

To make it work with files up to 100mb you need to have your host enable php to accept that big of files.


Here's a basic code (upload.php):


<?php

if ($_REQUEST['do']=='upload')
{
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], 'c:/www/uploads/'.basename($_FILES['uploadedfile']['name'])))
{
//Successful
}
else
{
//Not successful
}
}
else
{
?>

<form enctype="multipart/form-data" action="upload.php?do=upload" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="uploadedfile" />
<input type="submit" value="Upload!" />
</form>

<?php

}

?>

The contents of $_FILES (http://www.php.net/manual/en/reserved.variables.php#reserved.variables.files) from the example form is as follows. Note that this assumes the use of the file upload name userfile, as used in the example script above. This can be any name.
$_FILES['userfile']['name']
The original name of the file on the client machine.
$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.
$_FILES['userfile']['size']
The size, in bytes, of the uploaded file.
$_FILES['userfile']['tmp_name']
The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES['userfile']['error']This should get you started but remember there's more checks you'll need to do like file extension, file size, etc.
To just get info on what was uploaded try

print_r($_FILES);

If you need more info let me know what you want exactly and I can help.

hungrylilboy
08-15-2006, 09:55 PM
..