[PHP] scaling and uploading the pt 2

2007-09-20 Thread Hulf
This is the full code so far. The files are saving but they are not 
resizing.

Can anyone help? I need to get this

$myimage = imagejpeg($thumb);

into $target_path directory.


H.

--

if(isset($_POST['_upload'])   $_FILES['userfile']['size']  0)
{

$imageinfo = getimagesize($_FILES['userfile']['tmp_name']);

echo $width=$imageinfo[0];
echo $height=$imageinfo[1];


$newwidth = 300;
$newheight = 200;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['userfile']['tmp_name']);

// Resize
$myimage = imagecopyresized($thumb, $source, 0, 0, 0, 0, 300, 200, $width, 
$height);

// Output
$myimage = imagejpeg($thumb);

$target_path = ../property_images/$property_id/.basename( 
$_FILES['userfile']['name']);

$img_url= $property_id./.basename( $_FILES['userfile']['name']);

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
  /*  echo The file .  basename( $_FILES['userfile']['name']).
 has been uploaded;*/
} else{
echo There was an error uploading the file, please try again!;
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] scaling and uploading the pt 2

2007-09-20 Thread brian

Hulf wrote:
This is the full code so far. The files are saving but they are not 
resizing.


Can anyone help? I need to get this

$myimage = imagejpeg($thumb);

into $target_path directory.


H.

--

if(isset($_POST['_upload'])   $_FILES['userfile']['size']  0)
{

$imageinfo = getimagesize($_FILES['userfile']['tmp_name']);

echo $width=$imageinfo[0];
echo $height=$imageinfo[1];


$newwidth = 300;
$newheight = 200;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['userfile']['tmp_name']);

// Resize
$myimage = imagecopyresized($thumb, $source, 0, 0, 0, 0, 300, 200, $width, 
$height);


Don't assign to $myimage here. imagecopyresized() returns a boolean.


// Output
$myimage = imagejpeg($thumb);


Same here.

$target_path = ../property_images/$property_id/.basename( 
$_FILES['userfile']['name']);


I can't see how you're able to save the file using this path. 
move_uploaded_file() requires a path from server root (not DOCUMENT_ROOT).



$img_url= $property_id./.basename( $_FILES['userfile']['name']);

if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
  /*  echo The file .  basename( $_FILES['userfile']['name']).
 has been uploaded;*/
} else{
echo There was an error uploading the file, please try again!;
}


Here, you're saving the originally-uploaded file, not the re-sized 
version you created. You want to pass the path to imagejpeg() to have it 
save the new image at the destination (the 3rd param is the quality 
setting). Do:


// note, also, that you had the dest. width  height hard-coded.
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, 
$width, $height);


$target_path = // resolve this

if (imagejpeg($thumb, $target_path))
{
echo 'Huzzah!';
}
else
{   
echo 'back to php-general ...';
}

brian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php