Jump to content

Image Upload - How to restrict a size?


virtuexru

Recommended Posts

OK. I have an image upload form that works fine, I can limit the size of the file, but now I need to limit the users to a certain pixel range.

 

Something like size MUST be 50 x 50 pixels. Is there anyway to do this?

 

Here is the current code I have:

 

<?php
$uploadDir = '/xxx/xxx/public_html/xxx/userimages/';

if(isset($_POST['upload']))
{
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];

if($fileType == "image/jpeg")
      {
    // get the file extension first
    $ext      = substr(strrchr($fileName, "."), 1); 
    
    // generate the random file name
    $randName = md5(rand() * time());
    
    // and now we have the unique file name for the upload file
    $filePath = $uploadDir . $randName . '.' . $ext;
$fileEnc  = $randName . '.' . $ext;

    // move the files to the specified directory
    // if the upload directory is not writable or
    // something else went wrong $result will be false
    $result    = move_uploaded_file($tmpName, $filePath);
    if (!$result) {
        echo "Error uploading file";
        exit;
    }

    if(!get_magic_quotes_gpc())
    {
        $fileName  = addslashes($fileName);
        $filePath  = addslashes($filePath);
	$fileEnc   = addslashes($fileEnc);
    }  
include('config.php');
include('connect.php');

    $query = "INSERT INTO xxx VALUES ('', '$fileType', '$filePath', '$fileSize', '$fileName', '$fileEnc', '$user')";

    mysql_query($query) or die('Error, query failed : ' . mysql_error());                    

    include('close.php');
    
    echo "<br>File uploaded<br>";
  }
else
  {
  	echo "Image must be in JPEG format.";
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/45285-image-upload-how-to-restrict-a-size/
Share on other sites

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.