Jump to content

Image upload file types


rofl90

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.