First of all I am very new to php and this forum so excuse my stupidy if this is simple.
I found a tutorial for a simple PHP uploader, my site needs peopl to upload, jpeg, gif, doc, pdf and maybe even eps.
I found a tutorial and got this working....from a security aspect I'm not sure its great but its not running on my server and it works on my shared hosting so I hoping its ok.
My problem is the script I got only shows how to upload jpeg's of a certain size, I need to simple know how to edit the php to add the above file types and increase the size.
Changing the error messages etc I think I can work out for myself.
Here is the upload.php:
Code: Select all
<?php
//?heck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
($_FILES["uploaded_file"]["size"] < 10000000)) {
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'/file_store/'.$filename;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
}
} else {
echo "Error: Only .jpg images under 350Kb are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
?>
Code: Select all
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploaded_file" type="file" style="width:360px; " />
<input type="submit" value="Upload" />
</form>
Ryan