Help - Search - Members - Calendar
Full Version: What Am I Doing Wrong? Upload Script
Zymic Webmaster Forums > Zymic Free Web Hosting > Zymic Free Web Hosting - General Discussion & Help
Austin W80
Here's what I have in my upload.php file:

CODE
<?php
// Configuration - Your Options
$allowed_filetypes = array('.rar','.png','.zip','.jpg'); // These will be the types of file that will pass the validation.
$max_filesize = 5242880; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory).

$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');

// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');

// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');

// Upload the file to your specified path.
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
else
echo 'There was an error during the file upload. Please try again.'; // It failed sad.gif.

?>


I tried to upload a 3 MB RAR file, and it says my filetype isn't allowed. Try it yourself: http://austinw80.uuuq.com/upload/

What did I do wrong?

Also, how do I allow files larger than 2 MB to be uploaded via PHP?
Mael
Works fine for me! I just uploaded a blank rar file and I got "Your file upload was successful, view the file here". Are you sure you are actually uploading a rar file and not got a hidden extension on the end?

And what's wrong with uploading files larger than 2 MB?
Ed
Looking over this website, it looks like it won't be welcome on Zymic hosting:
  • Future linking to copyrighted content (Wii ISO's)
  • File hosting (upload script)

Convince us otherwise, or your site will be suspended. You have 1 day to reply.
Austin W80
I've removed the games.html. It was just a test to see what it would look like, sorry. As for the upload script, I was going to use it for uploading school files. You can continuously check back, there will be nothing illegal hosted on the site. Does that suffice?

This was my first time ever using HTML, and I just wanted to get a feel for it. You can delete the site if you really want to, but can you tell me beforehand so I can back it up? (I don't remeber where i got those buttons at. smile.gif )


By the way, you can close this. The upload script seems to work now. (Still don't know what was wrong before.)
Phoenyx
QUOTE(Austin W80 @ Aug 2 2009, 01:30 AM) *
Also, how do I allow files larger than 2 MB to be uploaded via PHP?

Maximum alowed file size is set by this variable..
QUOTE
$max_filesize = 5242880

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.