Jump to content

setting size 200px of upload?


wmguk

Recommended Posts

Hey guys,

 

I have a file upload script, but I want to specify maximum width and a maximum height of 200px (but not always square... may be 200px x 150px or 150px x 200px...)

 

this is my script, is there anything I can do to it?

 

<?
//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$imageid = $conamed . $imagename ;
$newimage = "../images/logo/" . $imageid ;

echo $newimage;

include 'scripts/connection.php';

if (!$con)
  {
  die('Could not connect: ' . mysql_error() );
  }
  mysql_select_db($db, $con);

//Run the update query
$sql = "UPDATE users SET logo = '$imageid' WHERE email = '$email'";

mysql_query( $sql , $con ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); 

$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}

}

?>


<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
<p><input name="image_file" type="file" class="button" size="20">
</p>
<p><input name="action" type="submit" class="button" value="Upload Image">
</p>
</form>

<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?>

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/122804-setting-size-200px-of-upload/
Share on other sites

I found

 

list($width, $height, $type, $attr) = getimagesize($_FILES['image_file']['name']);

if ($width > 200 || $height > 200)
{
echo "Maximum width and height exceeded. Please upload images below 200x200 px size";
exit();
}

 

however I added it but it doesnt stop the file upload...

you can only limit by filesize. once up you can check and reject, but i'd just resize it...

 

Oh ok :( thats a pain, will the quality of an image thats say 1000 px wide, and then resized down to 200px be affected or will it stay ok?

 

if it stays ok, how could I amend my script to resize after upload?

 

Thanks :)

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.