Jump to content

Recommended Posts

Using the GD Library, I'm trying to upload an image (but set to a MAX size), then copy that image and make a thumbnail set to a max size as well... I'm not sure what I'm doing wrong. Any suggestions?

 

//start testing phase PHP script

//using "SELECT OPTION" drop down list on form

//determine file type for proper image resizing

if ($_POST['file_type'] == "JPG"){

echo "File Type was JPG";

$filetype = "JPG";

} elseif ($_POST['file_type'] == "GIF"){

echo "File Type was GIF";

$filetype = "GIF";

} elseif ($_POST['file_type'] == "PNG"){

echo "File Type was PNG";

$filetype = "PNG";

}

 

 

//so "$srce1" BELOW knows what type of file to create

if ($filetype == JPG){

$createimage = imagecreatefromjpeg;

} elseif ($filetype == GIF){

$createimage = imagecreatefromgif;

} elseif ($filetype == PNG){

$createimage = imagecreatefrompng;

}

// This is the temporary file created by PHP

$uploadedfile = $_FILES['article_img']['tmp_name'];

 

// Create an Image from it so we can do the resize

$srce1 = $createimage($uploadedfile);

// Get image original size

list($width,$height)=getimagesize($uploadedfile);

 

// set image height/width

$newwidth=600;

$newheight=($height/$width)*600;

$tmp=imagecreatetruecolor($newwidth,$newheight);

 

// this line actually does the image resizing, copying from the original

// image into the $tmp image

imagecopyresampled($tmp,$srce1,0,0,0,0,$newwidth,$newheight,$width,$height);

 

// now write the resized image to disk. I have assumed that you want the

// resized, uploaded image file to reside in the ./images subdirectory.

$filename = $_SERVER['DOCUMENT_ROOT']."images/". $_FILES['article_img']['name'];

imagejpeg($tmp,$filename,100);

 

imagedestroy($srce1);

imagedestroy($tmp);

 

// NOTE: PHP will clean up the temp file it created when the request

// has completed.

//end testing phase php script

//all code below here works

 

 

//determine folder to upload images to and also

//post in SQL column "article_photo" the image location on server

$target_path = "/".images."/".$_POST['cat_id']."/";

 

$target_path = $_SERVER['DOCUMENT_ROOT'].$target_path . basename( $_FILES['article_img']['name']);

 

if(move_uploaded_file($_FILES['article_img']['tmp_name'], $target_path)) {

    echo "The file ".  basename( $_FILES['article_img']['name']).

    " has been uploaded";

$folder = "http://www.chexed.com/images/".$_POST['cat_id']."/".$_FILES['article_img']['name'];

} else{

//Give instruction in case image not uploaded

    echo "No Image File was uploaded.";

$folder = "0";

}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.