rofl90 Posted April 2, 2008 Share Posted April 2, 2008 It always says it's not allowed when the mysql says image/png;image/jpg;image/gif;image/jpeg Validater: <?php session_start (); include "config.php"; include "classes/settings.php"; include "classes/user.php"; include "classes/core.php"; if($user->check_login() == "0") { header("Location: index.php"); exit(); } if($user->user_type("uploadfile") == "0") { header("Location: notallowed.php"); exit(); } $target = $_POST['dir']; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; $uploaded_type = $_FILES['file']['type']; $chk_size = $db->query("SELECT max_size FROM settings"); $chk_size_a = $db->fetch_array($chk_size); if ($uploaded_size > $chk_size_a['max_size']) { header("Location: uploadfile.php?msg=Sorry the file you chose to upload was bigger than the specified size."); $ok=0; } $file_type_sql = $db->query("SELECT legal_ext FROM settings"); $file_type_arr = $db->fetch_array($file_type_sql); $file_things = $file_type_arr['legal_ext']; $file_bits = explode(";", $file_things); if(!in_array($uploaded_type)) { header("Location: uploadfile.php?msg=The file you have chosen to upload is not allowed as it is a ". $uploaded_type ." file, of which is not permitted."); $ok=0; } if($ok == 1) { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { header("Location: uploadfile.php?msggood=The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded successfully!"); } else { header("Location: uploadfile.php?msggood=The file ". basename( $_FILES['uploadedfile']['name']). " has not been uploaded, please try again, if the problem persists please contact your technical support."); } } ?> form: <?php if(isset($_GET['msg'])) { echo "<div class=\"error\">" . $_GET['msg'] ."</div>"; } elseif(isset($_GET['msggood'])) { echo "<div class=\"good\">" . $_GET['msggood'] ."</div>"; }?> <form enctype="multipart/form-data" action="upload_file.php" method="POST"> <fieldset> <legend>Directory</legend> <input type="text" name="dir" id="submit" value="../images" /> </fieldset> <fieldset> <legend>Browse File...</legend> <input id="textbox" name="uploadedfile" type="file" /> </fieldset> <fieldset> <legend>Finished?</legend> <input name="submit" type="submit" id="submit" value="Upload File" /> </fieldset> </form> Link to comment https://forums.phpfreaks.com/topic/99097-image-upload-file-types/ Share on other sites More sharing options...
rhodesa Posted April 2, 2008 Share Posted April 2, 2008 in_array needs 2 arguments. try changing this: if(!in_array($uploaded_type)) { to if(!in_array($uploaded_type,$file_bits)) { Link to comment https://forums.phpfreaks.com/topic/99097-image-upload-file-types/#findComment-507042 Share on other sites More sharing options...
teng84 Posted April 2, 2008 Share Posted April 2, 2008 if(!in_array($uploaded_type)) { i belive you missed on parameter using the function in array http://www.php.net/manual/en/function.in-array.php beaten to that Link to comment https://forums.phpfreaks.com/topic/99097-image-upload-file-types/#findComment-507043 Share on other sites More sharing options...
rofl90 Posted April 2, 2008 Author Share Posted April 2, 2008 OK that part works with: <?php session_start (); include "config.php"; include "classes/settings.php"; include "classes/user.php"; include "classes/core.php"; if($user->check_login() == "0") { header("Location: index.php"); exit(); } if($user->user_type("uploadfile") == "0") { header("Location: notallowed.php"); exit(); } $target = $_POST['dir']; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; $uploaded_type = $_FILES['file']['type']; $chk_size = $db->query("SELECT max_size FROM settings"); $chk_size_a = $db->fetch_array($chk_size); if ($uploaded_size > $chk_size_a['max_size']) { header("Location: uploadfile.php?msg=Sorry the file you chose to upload was bigger than the specified size."); $ok=0; } $file_type_sql = $db->query("SELECT legal_ext FROM settings"); $file_type_arr = $db->fetch_array($file_type_sql); $file_things = $file_type_arr['legal_ext']; $file_bits = explode(";", $file_things); if(!in_array($uploaded_type,$file_bits)) { header("Location: uploadfile.php?msg=The file you have chosen to upload is not allowed as it is a ". $uploaded_type ." file, of which is not permitted."); $ok=0; } if($ok == 1) { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { header("Location: uploadfile.php?msggood=The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded successfully!"); } else { header("Location: uploadfile.php?msg=The file ". basename( $_FILES['uploadedfile']['name']). " has not been uploaded, please try again, if the problem persists please contact your technical support."); } } ?> now whenever you upload something it gives off header("Location: uploadfile.php?msg=The file ". basename( $_FILES['uploadedfile']['name']). " has not been uploaded, please try again, if the problem persists please contact your technical support."); being an error as it can't move_uploaded_file() whats wrong with it guys? :S Link to comment https://forums.phpfreaks.com/topic/99097-image-upload-file-types/#findComment-507060 Share on other sites More sharing options...
rhodesa Posted April 2, 2008 Share Posted April 2, 2008 What is the value of $target when you eche it just before move_uploaded_file()? Make sure the webserver has access to write to that directory Link to comment https://forums.phpfreaks.com/topic/99097-image-upload-file-types/#findComment-507066 Share on other sites More sharing options...
rofl90 Posted April 2, 2008 Author Share Posted April 2, 2008 fixed i had all the $_FILES['this_was_wrong']['x']; .. Link to comment https://forums.phpfreaks.com/topic/99097-image-upload-file-types/#findComment-507072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.