Problem uploading file and opening with Adobe Fireworks.

I am having problems uploading file attached to my website
(Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /home/mywebsite/public_html/admin/add_upd_item.php on line 232)
and also opening in adobe fireworks
(Could not open file. Unknown file type).

testing.jpg
Not sure what is wrong with the file?
sabecsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
imagejpeg - should work with JPEG's
Image appears to be a PNG.

Are you sure you have not named a PNG as a JPG?
Ray PaseurCommented:
ImageJpeg(), ImagePng() and the like expect to work on an input image resource, returned by one of the image creation functions, such as imagecreatetruecolor() or imageCreateFromJPEG().  The expected inputs and outputs are documented in the online man pages at php.net.

Often this kind of problem arises because the uploaded image was not converted to an image resource correctly, but the script did not test for success or failure.  Instead the script assumed that the image resource existed.  Typically, when an image is converted to a resource PHP will return the resource or FALSE if the conversion fails.  The script needs to test for this and raise an exception when the failure occurs.

In the instant case, the image is named as if it were a JPG, but actually stored as a PNG.  Most of the time we can assume that the image file suffix is telling us the truth, but in this case it is not telling the truth.

Please see:
http://iconoun.com/demo/image_thumbnail.php?i=http://filedb.experts-exchange.com/incoming/2015/07_w29/923377/testing.jpg&w=300&h=300

The code snippet shows one way to get this right.  See lines 34-50 for the determination / fallback process.

<?php // demo/image_thumbnail.php

/**
 * http://www.experts-exchange.com/questions/28697317/Problem-uploading-file-and-opening-with-Adobe-Fireworks.html
 *
 * RESIZE AN IMAGE TO FIT INSIDE A DEFINED TRANSPARENT SPACE
 * USE CASE: <img src="image_thumbnail.php?i=your.jpg&w=150&h=100" />
 */
error_reporting(E_ALL);


// ACQUIRE THE ARGUMENTS - MAY WANT SOME SANITY TESTS HERE?
$thumb_w   = !empty($_GET["w"]) ? $_GET['w'] : 600;
$thumb_h   = !empty($_GET["h"]) ? $_GET['h'] : 400;
$image_url = !empty($_GET["i"]) ? $_GET['i'] : trigger_error("Missing GET argument 'i' for Image URL", E_USER_ERROR);;

// CREATE THE THUMBNAIL IMAGE RESOURCE AND FILL IN TRANSPARENT
$thumb = imagecreatetruecolor($thumb_w, $thumb_h);
imagesavealpha($thumb, TRUE);
$empty = imagecolorallocatealpha($thumb,0x00,0x00,0x00,127);
imagefill($thumb, 0, 0, $empty);

// GET ORIGINAL IMAGE DIMENSIONS
$array = getimagesize($image_url);
if ($array)
{
    list($image_w, $image_h) = $array;
}
else
{
    trigger_error("NO IMAGE $image_url", E_USER_ERROR);
}

// ACQUIRE THE ORIGINAL IMAGE
$image_ext = explode('.', $image_url);
$image_ext = end($image_ext);
$image_ext = trim(strtoupper($image_ext));
switch($image_ext)
{
    case 'JPG' :
    case 'JPEG' :
        $image = @imagecreatefromjpeg($image_url);
        if ($image) break;

    case 'PNG' :
        $image = @imagecreatefrompng($image_url);
        if ($image) break;

    default : trigger_error("UNKNOWN IMAGE TYPE: $image_url", E_USER_ERROR);
}

// GET THE LESSER OF THE RATIO OF THUMBNAIL H OR W DIMENSIONS
$ratio_w = ($thumb_w / $image_w);
$ratio_h = ($thumb_h / $image_h);
$ratio   = ($ratio_w < $ratio_h) ? $ratio_w : $ratio_h;

// COMPUTE THUMBNAIL IMAGE DIMENSIONS
$thumb_w_resize = $image_w * $ratio;
$thumb_h_resize = $image_h * $ratio;

// COMPUTE THUMBNAIL IMAGE CENTERING OFFSETS
$thumb_w_offset = ($thumb_w - $thumb_w_resize) / 2.0;
$thumb_h_offset = ($thumb_h - $thumb_h_resize) / 2.0;

// COPY THE IMAGE TO THE CENTER OF THE THUMBNAIL
imagecopyresampled
( $thumb
, $image
, $thumb_w_offset
, $thumb_h_offset
, 0
, 0
, $thumb_w_resize
, $thumb_h_resize
, $image_w
, $image_h
)
;

// SHOW THE NEW THUMB IMAGE
header('Content-type: image/png');
imagepng($thumb);

// RELEASE THE MEMORY USED BY THE RESOURCES
imagedestroy($thumb);
imagedestroy($image);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sabecsAuthor Commented:
Thanks for your comments, very much appreciated.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.