Jump to content

Thumbnails of a file


adam291086

Recommended Posts

Hello,

 

I have this upload script that creates thumbnails. But i keep getting the following errors

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/external_upload.php on line 107

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/external_upload.php on line 109

 

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/external_upload.php on line 115

 

Warning: Cannot modify header information - headers already sent by (output started at /home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/external_upload.php:107) in /home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/external_upload.php on line 122

 

here is the full script

<?php
require_once 'Classes/ExtendedFileManager.php';
require_once('config.inc.php');

$file = $_FILES['upload'];
$error = 0;
$size = 0.45;



if(!empty($file))
{

$dir = $_POST['dir'];
$target = "/home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/files".$dir."/".basename($file['name']) ;
$file_extension = strtolower(substr(strrchr($file['name'], "."), 1));
$max_size = $IMConfig['max_filesize_kb_image'];



//This is our limit file type condition
if(!in_array($file_extension, $IMConfig['allowed_image_extensions']))
    {
        $message = "Please make sure you are uploading the correct file type";
        if(is_file($file['tmp_name']))
        {
            unlink($file['tmp_name']);
        }
        $error = 1;

    }

else if (file_exists($target))
    {
        $error = 1;
        $message = "File alread exists";
         if(is_file($file['tmp_name']))
        {
            unlink($file['tmp_name']);
            
        }
    }


else if(!is_file($file['tmp_name']))
    {
        $message = "Pease make sure you are uploading a file";
        $error = 1;
        if(is_file($file['tmp_name']))
        {
            unlink($file['tmp_name']);
            $error = 1;
        }

    }

else if(!is_uploaded_file($file['tmp_name']))
    {
        $message = "Pease make sure you are uploading a file";
        $error = 1;
        if(is_file($file['tmp_name']))
        {
            unlink($file['tmp_name']);
        }
    }

else if($file['size']>($max_size*1024))
	{
		$message = "File size is too large. Max size is 10Mb";
            $error = 1;
            if(is_file($file['tmp_name']))
            {
                unlink($file['tmp_name']);
            }
	}

if ($error == 1)
{
    header('Location: http://rubberduckiee.webfactional.com/file/error_upload/'.$message);
}
else if (in_array($file_extension, array("jpg","bmp","jpeg")))
{
    if (move_uploaded_file($file['tmp_name'], $target))
    {
        // Get new dimensions
        list($width_orig, $height_orig) = getimagesize($target);

        if ($width_orig > $IMConfig['thumbnail_width'])
        {
            $width = $width_orig * $size;
        }
        else
        {
            $width = $width_orig;
        }
        if ($height_orig > $IMConfig['thumbnail_height'])
        {
            $height = $height * $size;
        }
        else
        {
            $height = $height_orig;
            
        }

        // Resample
        $image_p = imagecreatetruecolor($width, $height);
        $image   = imagecreatefromjpeg($target);
        imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

        $pathToThumbs = "/home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/files".$dir."/thumbnail/";
        $fname = "thumbnail_".$file['name'];


        if (imagejpeg($image_p, "{$pathToThumbs}{$fname}"))
        {
            header('Location: http://rubberduckiee.webfactional.com/file/browse');
        }
        else
        {
            $message = "file not uploaded";
            header('Location: http://rubberduckiee.webfactional.com/file/error_upload/'.$message);
            unlink($target);
            
        }
    }
}
else
{
    move_uploaded_file($file['tmp_name'], $target);
    header('Location: http://rubberduckiee.webfactional.com/file/browse');
}



}
?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/191472-thumbnails-of-a-file/
Share on other sites

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/rubberduckiee/webapps/editor/Xinha/plugins/ExtendedFileManager/external_upload.php on line 107

Without me having to look though all the code, just echo out the $width & $height.

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.