hasek522 Posted August 12, 2008 Share Posted August 12, 2008 Hi so i am trying to create a file uploader (specifically pictures). I am encountering some errors. If any one could help I would appreciate it. $_FILES['userfile'] is always coming up as being empty. Here is the HTML form: <form action="action/uploadpicaction.php" method="post"> <input name="userfile" type="file" /> <br /> <input type="Submit" name="Submit" id="Submit" value="Submit" /> </form> the php: $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg'); // These will be the types of file that will pass the validation. $max_filesize = 6992347; // Maximum filesize in BYTES (currently 5MB). $upload_path = 'userimages/'; // 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. echo '<h1>'. $_FILES['userfile'].' </h1>'; // 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.'); Quote Link to comment https://forums.phpfreaks.com/topic/119388-upload-file/ Share on other sites More sharing options...
void Posted August 12, 2008 Share Posted August 12, 2008 Your <form> tag is missing parameter enctype="multipart/form-data". Quote Link to comment https://forums.phpfreaks.com/topic/119388-upload-file/#findComment-615052 Share on other sites More sharing options...
hasek522 Posted August 12, 2008 Author Share Posted August 12, 2008 ok now im getting an error saying i need to CHMOD a directory to 777. Im not sure what exactly this means or how to do this. Quote Link to comment https://forums.phpfreaks.com/topic/119388-upload-file/#findComment-615059 Share on other sites More sharing options...
void Posted August 12, 2008 Share Posted August 12, 2008 you need to set the right permissions for the directory, where the pictures are uploaded. most FTP client software (eg. FileZilla, right click on dir/file -> File attributes) have this functionality. also - PHP: chmod("path/to/image/dir", 0777); (this should be done once.) Quote Link to comment https://forums.phpfreaks.com/topic/119388-upload-file/#findComment-615066 Share on other sites More sharing options...
hasek522 Posted August 12, 2008 Author Share Posted August 12, 2008 hmmm i tried all those and still no luck, any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/119388-upload-file/#findComment-615076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.