Welcome Guest, Not a member yet? Register   Sign In
Getting uploadify to work
#51

[eluser]Puspex[/eluser]
Hey everybody!

I did some modifications to Bob Sawyer's uploadify.php script, posted on http://www.reloadedpc.com/code-igniter/j...deigniter/
What i did is if u wish to upload images (jpg,gif,png) it uploads the images, resizes and crops them to your needs, and returns their names to the uploadify.php view.

Here is the complete code located in the base_url(). "js/uploadify/uploadify.php" .

I added:
Code:
function uploadImage($inputName, $uploadDir, $imageWidth = 500, $thumbWidth = 100, $thumbHeight = 100)
    {
        $image     = $_FILES[$inputName];
        $imagePath = '';
        $thumbnailPath = '';
        // if a file is given
        if (trim($image['tmp_name']) != '') {
            $ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']];
            // generate a random new file name to avoid name conflict
            //$imagePath = $image['name'];
            $mainImageName = md5(rand() * time());
            $imagePath = $mainImageName . ".$ext";
            list($width, $height, $type, $attr) = getimagesize($image['tmp_name']);
            // make sure the image width does not exceed the
            // maximum allowed width
            
            if (true && $width > $imageWidth) {
                $result    = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, $imageWidth);
                $imagePath = $result;
            } else {
                $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
            }    
            
            if ($result) {
                // create thumbnail
                //$thumbnailPath = $image['tmp_name'];
                //$thumbnailPath =  md5(rand() * time()) . ".$ext";
                $thumbnailPath =  $mainImageName . "_thumb" . ".$ext";
                $result = cropImage($thumbWidth, $thumbHeight, $uploadDir . $imagePath, $ext, $uploadDir . $thumbnailPath);
                //$result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
                // create thumbnail failed, delete the image
    
                if (!$result) {
                    unlink($uploadDir . $imagePath);
                    $imagePath = $thumbnailPath = '';
                } else {
                    $thumbnailPath = $result;
                }    
            } else {
                // the product cannot be upload / resized
                $imagePath = $thumbnailPath = '';
            }
        }
        return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
    }
    
    function createThumbnail($srcFile, $destFile, $width, $quality = 100)
    {
        $thumbnail = '';
        if (file_exists($srcFile)  && isset($destFile))
        {
            $size        = getimagesize($srcFile);
            $w           = number_format($width, 0, ',', '');
            $h           = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
    
            $thumbnail =  copyImage($srcFile, $destFile, $w, $h, $quality);
        }
        // return the thumbnail file name on sucess or blank on fail
        return basename($thumbnail);
    }
    
    /*
        Copy an image to a destination file. The destination
        image size will be $w X $h pixels
    */
    
    function copyImage($srcFile, $destFile, $w, $h, $quality = 75)
    {
        $tmpSrc     = pathinfo(strtolower($srcFile));
        $tmpDest    = pathinfo(strtolower($destFile));
        $size       = getimagesize($srcFile);
    
        if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
        {
            $destFile  = substr_replace($destFile, 'jpg', -3);
            $dest      = imagecreatetruecolor($w, $h);
            imageantialias($dest, TRUE);
        } elseif ($tmpDest['extension'] == "png") {
            $dest = imagecreatetruecolor($w, $h);
            imageantialias($dest, TRUE);
        } else {
            return false;
        }
        switch($size[2])
        {
            case 1:       //GIF
                $src = imagecreatefromgif($srcFile);
                break;
             case 2:       //JPEG
                $src = imagecreatefromjpeg($srcFile);
                break;
            case 3:       //PNG
                $src = imagecreatefrompng($srcFile);
                break;
            default:
                return false;
                 break;
        }
    
        imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
        switch($size[2])
        {
            case 1:
            case 2:
                imagejpeg($dest,$destFile, $quality);
                 break;
                case 3:
                imagepng($dest,$destFile);
        }
        return $destFile;
    }


Messages In This Thread
Getting uploadify to work - by El Forum - 03-25-2009, 08:12 AM
Getting uploadify to work - by El Forum - 03-27-2009, 10:51 PM
Getting uploadify to work - by El Forum - 03-28-2009, 08:16 AM
Getting uploadify to work - by El Forum - 04-04-2009, 05:13 AM
Getting uploadify to work - by El Forum - 04-04-2009, 10:01 AM
Getting uploadify to work - by El Forum - 04-06-2009, 02:45 PM
Getting uploadify to work - by El Forum - 04-10-2009, 09:43 AM
Getting uploadify to work - by El Forum - 04-10-2009, 02:16 PM
Getting uploadify to work - by El Forum - 04-11-2009, 08:14 AM
Getting uploadify to work - by El Forum - 04-11-2009, 09:28 AM
Getting uploadify to work - by El Forum - 04-11-2009, 12:26 PM
Getting uploadify to work - by El Forum - 04-11-2009, 02:41 PM
Getting uploadify to work - by El Forum - 04-15-2009, 08:28 AM
Getting uploadify to work - by El Forum - 05-29-2009, 04:16 PM
Getting uploadify to work - by El Forum - 05-29-2009, 05:12 PM
Getting uploadify to work - by El Forum - 05-29-2009, 07:17 PM
Getting uploadify to work - by El Forum - 05-30-2009, 03:13 AM
Getting uploadify to work - by El Forum - 05-30-2009, 06:08 AM
Getting uploadify to work - by El Forum - 05-31-2009, 08:33 PM
Getting uploadify to work - by El Forum - 06-23-2009, 07:31 PM
Getting uploadify to work - by El Forum - 06-29-2009, 07:46 PM
Getting uploadify to work - by El Forum - 07-08-2009, 01:05 PM
Getting uploadify to work - by El Forum - 07-09-2009, 03:08 AM
Getting uploadify to work - by El Forum - 07-09-2009, 08:04 AM
Getting uploadify to work - by El Forum - 07-09-2009, 09:20 AM
Getting uploadify to work - by El Forum - 07-09-2009, 10:25 AM
Getting uploadify to work - by El Forum - 07-09-2009, 11:35 PM
Getting uploadify to work - by El Forum - 07-10-2009, 05:01 AM
Getting uploadify to work - by El Forum - 07-10-2009, 06:20 AM
Getting uploadify to work - by El Forum - 07-10-2009, 10:19 AM
Getting uploadify to work - by El Forum - 07-12-2009, 08:10 PM
Getting uploadify to work - by El Forum - 07-12-2009, 08:19 PM
Getting uploadify to work - by El Forum - 07-14-2009, 10:17 AM
Getting uploadify to work - by El Forum - 07-23-2009, 01:07 AM
Getting uploadify to work - by El Forum - 07-28-2009, 03:45 AM
Getting uploadify to work - by El Forum - 07-28-2009, 03:50 AM
Getting uploadify to work - by El Forum - 07-28-2009, 02:34 PM
Getting uploadify to work - by El Forum - 08-24-2009, 08:14 AM
Getting uploadify to work - by El Forum - 09-29-2009, 11:39 AM
Getting uploadify to work - by El Forum - 09-29-2009, 10:10 PM
Getting uploadify to work - by El Forum - 09-30-2009, 08:50 AM
Getting uploadify to work - by El Forum - 10-01-2009, 02:51 PM
Getting uploadify to work - by El Forum - 10-08-2009, 11:07 PM
Getting uploadify to work - by El Forum - 10-09-2009, 07:17 AM
Getting uploadify to work - by El Forum - 10-09-2009, 10:24 AM
Getting uploadify to work - by El Forum - 10-14-2009, 12:38 PM
Getting uploadify to work - by El Forum - 10-14-2009, 01:59 PM
Getting uploadify to work - by El Forum - 10-18-2009, 03:32 AM
Getting uploadify to work - by El Forum - 10-26-2009, 01:53 PM
Getting uploadify to work - by El Forum - 10-30-2009, 03:59 AM
Getting uploadify to work - by El Forum - 11-17-2009, 06:40 AM
Getting uploadify to work - by El Forum - 11-17-2009, 06:42 AM
Getting uploadify to work - by El Forum - 11-17-2009, 08:47 AM
Getting uploadify to work - by El Forum - 11-18-2009, 06:18 AM
Getting uploadify to work - by El Forum - 11-18-2009, 10:35 AM
Getting uploadify to work - by El Forum - 11-21-2009, 11:57 AM
Getting uploadify to work - by El Forum - 11-22-2009, 03:20 AM
Getting uploadify to work - by El Forum - 11-23-2009, 08:09 AM
Getting uploadify to work - by El Forum - 11-24-2009, 02:57 AM
Getting uploadify to work - by El Forum - 11-24-2009, 04:04 AM
Getting uploadify to work - by El Forum - 11-24-2009, 04:08 AM
Getting uploadify to work - by El Forum - 11-24-2009, 05:24 AM
Getting uploadify to work - by El Forum - 11-24-2009, 08:10 AM
Getting uploadify to work - by El Forum - 11-24-2009, 02:30 PM
Getting uploadify to work - by El Forum - 11-24-2009, 08:23 PM
Getting uploadify to work - by El Forum - 11-25-2009, 01:29 AM
Getting uploadify to work - by El Forum - 11-25-2009, 03:22 AM
Getting uploadify to work - by El Forum - 11-25-2009, 05:27 AM
Getting uploadify to work - by El Forum - 11-25-2009, 05:42 AM
Getting uploadify to work - by El Forum - 11-25-2009, 07:35 AM
Getting uploadify to work - by El Forum - 11-25-2009, 07:58 AM
Getting uploadify to work - by El Forum - 11-25-2009, 08:41 AM
Getting uploadify to work - by El Forum - 12-01-2009, 01:17 PM
Getting uploadify to work - by El Forum - 12-03-2009, 02:52 AM
Getting uploadify to work - by El Forum - 12-03-2009, 06:13 AM
Getting uploadify to work - by El Forum - 12-03-2009, 07:41 PM
Getting uploadify to work - by El Forum - 12-03-2009, 10:56 PM
Getting uploadify to work - by El Forum - 12-04-2009, 12:55 AM
Getting uploadify to work - by El Forum - 12-04-2009, 08:36 AM
Getting uploadify to work - by El Forum - 12-15-2009, 10:10 PM
Getting uploadify to work - by El Forum - 12-16-2009, 07:41 AM
Getting uploadify to work - by El Forum - 12-31-2009, 02:12 AM
Getting uploadify to work - by El Forum - 12-31-2009, 02:45 PM
Getting uploadify to work - by El Forum - 01-01-2010, 08:26 AM
Getting uploadify to work - by El Forum - 01-02-2010, 12:59 AM
Getting uploadify to work - by El Forum - 01-12-2010, 11:40 PM
Getting uploadify to work - by El Forum - 01-12-2010, 11:44 PM
Getting uploadify to work - by El Forum - 01-12-2010, 11:47 PM
Getting uploadify to work - by El Forum - 01-12-2010, 11:59 PM
Getting uploadify to work - by El Forum - 01-13-2010, 12:19 AM
Getting uploadify to work - by El Forum - 01-17-2010, 12:10 PM
Getting uploadify to work - by El Forum - 01-17-2010, 02:35 PM
Getting uploadify to work - by El Forum - 01-17-2010, 02:55 PM
Getting uploadify to work - by El Forum - 01-17-2010, 04:14 PM
Getting uploadify to work - by El Forum - 01-22-2010, 06:13 AM
Getting uploadify to work - by El Forum - 01-26-2010, 08:41 AM
Getting uploadify to work - by El Forum - 03-06-2010, 05:51 PM
Getting uploadify to work - by El Forum - 03-07-2010, 02:03 AM
Getting uploadify to work - by El Forum - 03-08-2010, 07:57 AM
Getting uploadify to work - by El Forum - 03-13-2010, 07:00 PM
Getting uploadify to work - by El Forum - 03-13-2010, 11:57 PM
Getting uploadify to work - by El Forum - 06-08-2010, 02:54 AM
Getting uploadify to work - by El Forum - 06-08-2010, 07:01 AM
Getting uploadify to work - by El Forum - 06-14-2010, 03:54 AM
Getting uploadify to work - by El Forum - 06-14-2010, 06:51 AM
Getting uploadify to work - by El Forum - 06-14-2010, 07:27 AM
Getting uploadify to work - by El Forum - 06-14-2010, 01:01 PM
Getting uploadify to work - by El Forum - 06-14-2010, 03:08 PM
Getting uploadify to work - by El Forum - 06-15-2010, 03:39 AM
Getting uploadify to work - by El Forum - 06-15-2010, 05:47 AM
Getting uploadify to work - by El Forum - 07-08-2010, 01:41 PM
Getting uploadify to work - by El Forum - 08-07-2010, 12:37 AM
Getting uploadify to work - by El Forum - 11-10-2010, 10:26 AM
Getting uploadify to work - by El Forum - 11-10-2010, 10:31 AM
Getting uploadify to work - by El Forum - 11-10-2010, 10:34 AM
Getting uploadify to work - by El Forum - 11-10-2010, 10:52 AM
Getting uploadify to work - by El Forum - 11-10-2010, 10:59 AM
Getting uploadify to work - by El Forum - 11-11-2010, 03:00 AM
Getting uploadify to work - by El Forum - 11-11-2010, 06:04 AM
Getting uploadify to work - by El Forum - 01-28-2011, 04:11 AM
Getting uploadify to work - by El Forum - 03-25-2011, 06:16 AM
Getting uploadify to work - by El Forum - 03-28-2011, 08:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB