Jump to content

Recommended Posts

It was working fine until i added the image crop code...

 

<?
if($_POST['ponerfotos']){
$cuan = $_POST['cuan'];
for ($i=1; $i<=$cuan; $i++){
	$cantfoto=$_POST['cantfoto'];
	for ($j=1; $j<=$cantfoto; $j++){
		$file_tmp_name = $HTTP_POST_FILES['imagen_'.$i.'_'.$j]['tmp_name'];
		$file_name = $HTTP_POST_FILES['imagen_'.$i.'_'.$j]['name'];
		$valid = array (".jpg",".jpeg");
		$random_digit=rand(00000,99999);
		$new_file_name=$random_digit.$file_name;
		$path= "/home/content/m/i/l/miligraf/html/jaimev/img_anuncios/".$new_file_name;
		$img= "http://www.miligraf.com/jaimev/img_anuncios/".$new_file_name;

		$pathcrop= "/home/content/m/i/l/miligraf/html/jaimev/img_anuncios/crop/".$new_file_name;
		$imgcrop= "http://www.miligraf.com/jaimev/img_anuncios/crop/".$new_file_name;

		if(copy($file_tmp_name, $path)){
			$type = strtolower(strstr($file_name, '.'));
			if (!in_array($type, $valid)){
				echo 'La imágen #'.$j.' del anuncio #'.$i.'no es un archivo .jpg ó .jpeg, porfavor vuelva a subir dicha imágen.';
				unlink($path);
			}else{
				list($width, $height)=getimagesize($path);
				if ($width>550){
					$nuevowidth=550;
					$nuevoheight=($height*550)/$width;
					$resized_img = imagecreatetruecolor($nuevowidth,$nuevoheight);
					$new_img = imagecreatefromjpeg($file_tmp_name);
					imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $nuevowidth, $nuevoheight, $width, $height);
					imagejpeg($resized_img,$path);
					imagedestroy($resized_img);
					imagedestroy($new_img);
				}
				$cropwidth = 100;
				$cropheight = 75;
				$newwidth = $width / 2;
				$newheight = $height / 2;
				$cropLeft = ($newwidth/2) - ($cropwidth/2);
				$cropHeight = ($newheight/2) - ($cropheight/2);
				$canvas = imagecreatetruecolor($cropwidth,$cropheight);
				$piece = imagecreatefromjpeg($file_tmp_name);
				imagecopyresized($canvas, $piece, 0,0, $cropLeft, $cropHeight, $cropwidth, $cropheight, $newwidth, $newheight);
				imagejpeg($canvas,$pathcrop,90);
				imagedestroy($canvas);
				imagedestroy($piece);
			}
		}
	}
} ?>
<img src="<? echo $img; ?>" ><br/><br/>
<img src="<? echo $imgcrop; ?>" >
<? }else{ ?>
<div class="pasos"><span>Paso 1</span> > <span>Paso 2</span> > Paso 3<br/>
Subir imágenes de anuncio(s).</div>							
<br/>
<? 	include('conbd.php');
$query="SELECT cantfoto FROM stats WHERE ip='$user'";
extract($row = mysql_fetch_array(mysql_query($query))) or die ("Error: $query. " . mysql_error()); ?>
Tu cuenta solo te permite subir <? echo $cantfoto; ?> fotos por anuncio y las imágenes deben ser .jpg ó .jpeg
<br/><br/>
<div align="left">
<form action="" method="post" enctype="multipart/form-data">
<?	$cuan = $_POST['cuan'];
for ($i=1; $i<=$cuan; $i++){ ?>
	<div class="mayuscula"><strong>Anuncio #<? echo $i; ?></strong></div><br/>
	<? for ($j=1; $j<=$cantfoto; $j++){ ?>
		Imágen #<? echo $j; ?>
		<input name="imagen_<? echo $i;?>_<? echo $j; ?>" type="file" class="campo" size="85%"><br/>
	<? }?>
	<br/>
<? 	} ?>
<input type="hidden" name="cuan" value="<? echo $cuan; ?>">
<input type="hidden" name="cantfoto" value="<? echo $cantfoto; ?>">
<input name="ponerfotos" type="Submit" class="campo" value="Agregar"> <input type="reset" class="campo" value="Limpiar"></form>
</div>
<? } ?>

 

What could it have wrong?!

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/75316-image-resize-and-crop-problem/
Share on other sites

Yeah, i knew i forgot something lol.

 

After the image is uploaded and it is resized and a thumbnail created, it is supposed to show the images but i only get a blank page and when i look at the code i have this:

 

<img src="http://www.miligraf.com/jaimev/img_anuncios/69063">

 

It only posts the random number but the name should be a random number and the original name of the image, also the file type (jpg) is missing.

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.