mjahkoh Posted December 8, 2007 Share Posted December 8, 2007 I got this upload class here but gives an error "The file extension is invalid, please try again! " even when the extension is ok. Please i need your help. //begin testupload.php file //================== <?php if($_POST['Submit']){ echo "<h1>sawa</h1>"; //$_FILES['upload']['name'] //echo "<h1>$_POST['Submit']</h1>"; include("class/upload.php"); ///start $upload_class = new Upload_Files; //$upload_class->temp_file_name = trim($_FILES['upload']['tmp_name']); //$upload_class->file_name = trim(strtolower($_FILES['upload']['name'])); $upload_class->temp_file_name = trim($_FILES['tempfilename']); $upload_class->file_name = trim(strtolower($_FILES[$_POST['file']])); $upload_class->upload_dir = "uploads/"; $upload_class->upload_log_dir = "uploads/upload_logs/"; $upload_class->max_file_size = 5242880; $upload_class->banned_array = array(""); $upload_class->ext_array = array(".zip",".rar",".ace",".tar","*.jpg"); $valid_ext = $upload_class->validate_extension(); $valid_size = $upload_class->validate_size(); $valid_user = $upload_class->validate_user(); $max_size = $upload_class->get_max_size(); $file_size = $upload_class->get_file_size(); $file_exists = $upload_class->existing_file(); if (!$valid_ext) { $result = "The file extension is invalid, please try again!"; } elseif (!$valid_size) { $result = "The file size is invalid, please try again! The maximum file size is: $max_size and your file was: $file_size"; } elseif (!$valid_user) { $result = "You have been banned from uploading to this server."; } elseif ($file_exists) { $result = "This file already exists on the server, please try again."; } else { $upload_file = $upload_class->upload_file_with_validation(); if (!$upload_file) { $result = "Your file could not be uploaded!"; } else { $result = "Your file has been successfully uploaded to the server."; } } echo $_POST['file'] ; echo $result ; //end } ?> //================== //end testupload.php file The upload class is attached here [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Seraph Posted December 8, 2007 Share Posted December 8, 2007 $upload_class->ext_array = array(".zip",".rar",".ace",".tar","*.jpg"); get rid of the asterik in *.jpg Quote Link to comment Share on other sites More sharing options...
mjahkoh Posted December 8, 2007 Author Share Posted December 8, 2007 jus did that. Nothing doing. Where Should i put the /upload and uploads/upload_logs/ directorys. In the htdocs or in my sites folder in htdocs Quote Link to comment Share on other sites More sharing options...
Seraph Posted December 8, 2007 Share Posted December 8, 2007 you should put it in the same dir as the script Quote Link to comment Share on other sites More sharing options...
mjahkoh Posted December 10, 2007 Author Share Posted December 10, 2007 ive decided to paste the entire code here. Please see why it doesnt upload yet i got the directory "uploads" and "uploads/logs" . //Start Upload file <?php if($_POST['Submit']){ include("class/upload.php"); $upload_class = new Upload_Files; $upload_class->temp_file_name = trim($_FILES['tempfilename']); $upload_class->file_name = trim(strtolower($_FILES[$_POST['file']])); $upload_class->upload_dir = "uploads/"; $upload_class->upload_log_dir = "uploads/upload_logs/"; $upload_class->max_file_size = 5242880; $upload_class->banned_array = array(""); $upload_class->ext_array = array(".zip",".rar",".ace",".tar",".jpg"); $valid_ext = $upload_class->validate_extension(); $valid_size = $upload_class->validate_size(); $valid_user = $upload_class->validate_user(); $max_size = $upload_class->get_max_size(); $file_size = $upload_class->get_file_size(); $file_exists = $upload_class->existing_file(); if (!$valid_ext) { $result = "The file extension is invalid, please try again!"; } elseif (!$valid_size) { $result = "The file size is invalid, please try again! The maximum file size is: $max_size and your file was: $file_size"; } elseif (!$valid_user) { $result = "You have been banned from uploading to this server."; } elseif ($file_exists) { $result = "This file already exists on the server, please try again."; } else { $upload_file = $upload_class->upload_file_with_validation(); if (!$upload_file) { $result = "Your file could not be uploaded!"; } else { $result = "Your file has been successfully uploaded to the server."; } } echo $result ; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>uploadings </title> </head> <body> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> <input type="file" name="file" /> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> //end upload file [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 Is the script spitting out any errors? You might want to try an absolute path to your upload dirs and see if that works. Quote Link to comment Share on other sites More sharing options...
mjahkoh Posted December 10, 2007 Author Share Posted December 10, 2007 am new to php what would be the absolute path be. In addition , how do i read the filename of the file that I upload. ? Thanks Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 Change these and it should work $upload_class->temp_file_name = trim($_FILES['tempfilename']); $upload_class->file_name = trim(strtolower($_FILES[$_POST['file']])); to $upload_class->temp_file_name = trim($_FILES['file']['tmp_name']); $upload_class->file_name = trim(strtolower($_FILES['file']['name'])); Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 Use $_FILES like this $_FILES['name of the file input in your form'] * $_FILES["file"]["name"] - the name of the uploaded file * $_FILES["file"]["type"] - the type of the uploaded file * $_FILES["file"]["size"] - the size in bytes of the uploaded file * $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server * $_FILES["file"]["error"] - the error code resulting from the file upload Quote Link to comment 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.