Jump to content

almost finished, one error, help please


luismc2007

Recommended Posts

Hi, good morning.

 

I have this code attached that is almost finished ready to work... ( sorry, is coded in spanish language )

 

But, at the end I have an error and don´t know how to fix...

 

I´m, trying to copy and save the new image created "$final" with a new name "$lapeque", but doesn´t work.

 ( At comment: //PASO LA IMAGEN CREADA PEQUEÑA Y LA GRABO EN LA CARPETA DESTINOFINAL )

 

This code is without errors and runs to the end "echo[FIN]".

 

Any idea??

 

Can you help me? please.

 

Thanks a lot.

 

Regards

 

resizer.php.

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/278312-almost-finished-one-error-help-please/
Share on other sites

Hi: Yes, this is the code and echos in english, sorry and thanks for everybody

 

 

<?php

if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
  echo "File uploades: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Weight: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  }

$archivo=$_SERVER['DOCUMENT_ROOT']."/test/arriba/".$_FILES["file"]["name"];
echo "The file is: $archivo<br>";

echo "Copying file in destiny<br>";
move_uploaded_file($_FILES["file"]["tmp_name"], $archivo);
echo "Fichero imagen copiado<br>";

//Get the size of the original image

list($ancho,$alto)=getimagesize($archivo);

 

$anchooriginal=$ancho;
echo "Original width: $anchooriginal<br>";

$altooriginal=$alto;
echo "OriginalHeight: $altooriginal<br>";

 

// What is the image...
$separo = explode( '.', strtolower($archivo) );
$nombre = $separo[0];
$extension = $separo[1];

 

echo "Name: $nombre<br>";
echo "Extension: $extension<br>";

 

//My Final size for thumb
$ancho_final="200";
$alto_final="150";

 

// Create a new jpg image
$imagen_src = imagecreatefromjpeg( $archivo );
echo "ok, new image created in jpg format<br>";

//scaling and calculating size of image
$escala_1=1;
$escala_2=1;
$escala_1=$ancho_final/$anchooriginal;
$escala_2=alto_final/$altooriginal;

 

echo "New Sizes: $escala_1, $escala_2 <br>";

 

//Let see if vertical or horizontal

 

if ( $altooriginal > $anchooriginal )
 {
 $escala_1 = $escala_2;
 }

echo"Ok, scaling complete vertical-horizontal<br>";

 

// scaling

$horizontal=ceil( $anchooriginal * $escala_1 );
$vertical=ceil( $altooriginal * $escala_1 );

echo"The new scale is: $horizontal, $vertical<br>";

 

//create new image
$final=imagecreatetruecolor ( $horizontal, $vertical );

echo"The new image is created<br>";

 

//copying the new image into teh new small image

imagecopyresized ( $final, $imagen_src, 0, 0, 0, 0, $horizontal, $vertical, imagesx($imagen_src), imagesy($imagen_src) );

echo"Copied<br>";

$destinofinal=$_SERVER['DOCUMENT_ROOT']."/test/arriba/";
echo "Copying file into final destiny: $destinofinal<br>";

//The new name for thumb

$cadenapeque="p.jpg";
$extraigo=substr($final,0,-4);
$lapeque=$extraigo.$cadenapeque;
echo "The thumb is: $lapeque<br>";

 

//creating
imagejpeg($final,$lapeque);

 

//The thumb that I want to copy and save in the server

copy($lapeque, $destinofinal);
echo "Image saved in destiny<br>";

echo"closing...<br>";

imagedestroy ($final);

 

echo"END<br>";
 
?>

 

I think my error is around this comment line:

//The thumb that I want to copy and save in the server

 

Thanks.

When I run your script into my server I got next errors:

 

1. Notice: Use of undefined constant alto_final - assumed 'alto_final' in .... you're using - $escala_2=alto_final/$altooriginal (don't forget a dollar sign)

 

2. Warning: substr() expects parameter 1 to be string, resource given in ...

 

3. Warning: copy(): The second argument to copy() function cannot be a directory in ...

 

Double check the script and redesign it, also use a code tags next time, please! 

Oh,

 

Dollar sign... jeje.. just forget it and don´t see it. :-) (sorry)

now is ok...

     $escala_1=$ancho_final/$anchooriginal;
     $escala_2=$alto_final/$altooriginal;

 

 

About the substr() function.... I think $final (first argument) is the "name" of the image that I create... or not? What I´m doing wrong with this?

 

Thanks.

 

 

About the substr() function.... I think $final (first argument) is the "name" of the image that I create... or not? What I´m doing wrong with this?

 

You have to know what type of value expect to be the $final variable.

 

Check :

 

echo gettype($final);

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.