Jump to content

resizing uploaded images


philhxc

Recommended Posts

could anyone help me by adding a image resize to the following script please.. the the size must be 345px width or 345px height keeping aspect ratio...  i dont know if this is really hard or take too much time, but i dont know anything about php, so if someone could help me i would appreciated soooo much..

 

thanks

 

the code:

 

<?php
//session_start();
include("./admin/config.php");
include("$include_path/common.php");

global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SESSION_VARS,$HTTP_POST_FILES;
global $_SESSION;

if ($HTTP_POST_VARS!="")
    $_POST=$HTTP_POST_VARS;

if ($HTTP_GET_VARS!="")
    $_GET=$HTTP_GET_VARS;

if ($HTTP_SESSION_VARS!="")
   $_SESSION=$HTTP_SESSION_VARS;

if ($HTTP_POST_FILES!="")
   $_FILES=$HTTP_POST_FILES;


check_user_login();

$img_src = "";

include("$include_path/$table_file");

if(isset($_POST['delete_image']))
{

$sql = "
	select
		concat(id, '.', image_ext) as image
	from
		$tb_users
	where
		id = '$_SESSION[userid]'
";
$query = mysql_query($sql) or die(mysql_error());

$file = $image_path . "/" . mysql_result($query, 0, "image");

if(file_exists($file))
{

	if(unlink($file)){
		drop_rotation($_SESSION['userid']);
		set_notfound_image($_SESSION['userid']);
		$message = "Tu foto ha sido borrada.";
	} else {
		$message = "Ha ocurrido un error, tu foto no se ha podido borrar.";
	}

} else {
	$message = "No se encontro ninguna foto.";
}
}

if(isset($_POST['upload_image']))
{

$sql = "
			select
				total_files
			from
				$tb_users
			where
				id = '$_SESSION[userid]'
";
$query = mysql_query($sql) or die(mysql_error());
$total = mysql_result($query, 0, "total_files");

if ($total <= 20) 
{

	$sql = "
		select
			image_status
		from
			$tb_users
		where
			id = '$_SESSION[userid]'
	";
	$query = mysql_query($sql) or die(mysql_error());

	$res = mysql_fetch_array($query);
	if ($res['image_status']!="disabled")
	{

		$upload_image_error = false;
		$allowed = false;

		$the_file_ext_array = explode(".", $_FILES['the_file']['name']);
		$the_file_ext = $the_file_ext_array[sizeof($the_file_ext_array)-1];

		if(!strlen($_FILES['the_file']['name'])) 
		{

			$upload_image_error = true;
			$message = "No subiste nada!<br><br>";

		}

		$sql = "
			select
			*
			from
			$tb_image_types
		";
		$query = mysql_query($sql) or die(mysql_error());

		while($array = mysql_fetch_array($query))
			if($the_file_ext == $array["ext"]) $allowed = true;

		if(!$allowed)
		{

			$upload_image_error = true;

			$message = "El tipo de archivo no es permitido<br>solo puedes subir:<br><br>";

			$ssql = "
				select
					*
				from
					$tb_image_types
			";
			$squery = mysql_query($ssql) or die(mysql_error());

			while($sarray = mysql_fetch_array($squery))
				$message .= "." . $sarray["ext"] . "<br>";

		}

		if($allowed)
		{

		// echo " tmp ".$_FILES['the_file']['tmp_name'];

			$size = getimagesize($_FILES['the_file']['tmp_name']);
			list($foo, $width, $bar, $height) = explode("\"", $size[3]);

			if($width > $max_image_width)
			{

				$upload_image_error = true;

				$message = "Tu imagen no puede ser mas de " . $max_image_width . " píxeles de ancho<br><br>";
			}

			if($height > $max_image_height)
			{

				$upload_image_error = true;

				$message = "Tu imagen no puede ser mas de " . $max_image_height . " píxeles de alto<br><br>";
			}

		}

		if(!$upload_image_error)
		{
			$sql = "
				select
					total_files
				from
					$tb_users
				where
					id = '$_SESSION[userid]'
			";
			$query = mysql_query($sql) or die(mysql_error());
			$total = mysql_result($query, 0, "total_files");
			$number = $total + 1;
			$main_picture= $_POST['pic_type'];

			if($total && $main_picture=="y") {
				$number=1;
			}				
			$file_name = $_SESSION['userid'] . "_$number." . $the_file_ext;

			if(isset($_POST['overwrite']))
			{
				if(move_uploaded_file($_FILES['the_file']['tmp_name'], $image_path . "/" . $file_name)) 
				{
					if($main_picture=="y") {
                		                        update_ext($the_file_ext, $_SESSION['userid']);
					}
					$newest_sql ="select * from $tb_newest_pictures where user_id ='$_SESSION[userid]' and image_number ='$number' ";
					$newest_res = mysql_query($newest_sql);
					if(mysql_num_rows($newest_res) ) {
						$newest_picture_sql ="update $tb_newest_pictures set upload_time=now() where user_id ='$_SESSION[userid]' and image_number ='$number' ";
						mysql_query($newest_picture_sql);
						echo mysql_error();	
					} 
					else {
						$newest_picture_sql ="insert into  $tb_newest_pictures(user_id,image_number,upload_time) values ('$_SESSION[userid]','$number',now() ) ";
						mysql_query($newest_picture_sql);
						echo mysql_error();	
					}
			if ($automatically_approve_picture=="no"){
					$message = "Tu foto se subio eitosamente. Porfavor espera 24 horas hasta que sea revisada."; }
			else {
					$message = "Tu imagen fue subida exitosamente."; }

				                        $uid=$_SESSION['userid'];
              			          		        $main=$_POST['pic_type'];

			                                if($main == "n")
                					                $desc=$_POST['pic_desc'];
				                                $sql="insert into $tb_upload_image_details (id,user_id,total_file_count,main,description)
										values('',$uid,$number,'$main','$desc')";

	                		                mysql_query($sql);
					if($main == "n") {	
						$sql = "update $tb_users set total_files=total_files+1 where id = '$_SESSION[userid]' ";
						$query = mysql_query($sql) or die(mysql_error());
					}
					else {
					     if(!$total) {	
						$sql = "update $tb_users set total_files=total_files+1 where id = '$_SESSION[userid]' ";
						$query = mysql_query($sql) or die(mysql_error());
					     }	
					}

				} 
				else 
				{

					$message = "Tu imagen no se pudo subir, ocurrió un error de escritura.";	
				}


				update_url("here", "", $_SESSION['userid']);

				if ($automatically_approve_picture=="yes")
					    approve_image($_SESSION['userid']);
				else 
					    queue_image($_SESSION['userid']);

				$imgsrc="$dat_base_url/images/$file_name";

				NewImageAddedNotification($_SESSION['userid'], $imgsrc);
			}
			else 
			{

				if (!@copy($_FILES['the_file']['tmp_name'], $image_path . "/" . $file_name))
				{

					$message = "Tu nueva foto no se pudo subir.";	

				} 
				else 
				{

					$message = "Tu nueva imagen fue subida exitosamente.";
					update_ext($the_file_ext, $_SESSION['userid']);

				}

				update_url("here", "", $_SESSION['userid']);

				if ($automatically_approve_picture=="yes")
				    approve_image($_SESSION['userid']);
				else
				    queue_image($_SESSION['userid']);

				$imgsrc="$dat_base_url/images/$file_name";

				NewImageAddedNotification($_SESSION['userid']);

			}
		} // if (uploade_image_error)

	} // if (disabled)
	else
	{
		$message = "Tu foto fue desabilitada por el administrador.";
	}
}
else
{
	$message = "Exediste el limite para subir imagenes...";
}
}

if(isset($_POST['submit_image_url'])){
$message = del_image($_SESSION[userid]);
$message = update_url($_POST['update_where'], $_POST['new_image_url'], $_SESSION['userid']);

}

include("$include_path/doc_head.php");
include("$include_path/styles.php");


include ("Ads_new.php");
include("$include_path/right.php");
include("$include_path/left.php");


// start content


$form = "";
$location = "";

if(isset($message)){
$message_code = <<<EOF
<table cellpadding="5" cellspacing="5" border="0">
<tr>
<td class="s9">$message</td>
</tr>
</table>
EOF;
}

$user_id = isset($_SESSION['userid']) ? $_SESSION['userid'] : 0;

$image_src = get_image($user_id,3);

include("$include_path/image_rules.php");
$image_code = $image_rules;


$tpl->assign(array('IMAGE_SRC' => $image_src));
$tpl->parse('IMAGE_CODE', 'upload_image_code');
$image_code .= $tpl->fetch('IMAGE_CODE');


if($allow_local_image == 1){
  $tpl->assign(array('MAX_IMAGE_SIZE' => $max_image_size));
  
  $location = query_where($user_id);
  
  if($location == "here" || !$allow_remote_image){
    $tpl->assign(array('CHECKED_LOCAL_IMAGE' => ' checked'));
  	$img_src = "";
  }
  
  $tpl->parse('FIELD_LOCAL_IMAGES', 'field_local_image');
} else {
  $tpl->clear_dynamic('field_local_image');
}

if($allow_remote_image == 1){
  if($location == "there" or $allow_local_image == 0) {
    $tpl->assign(array('CHECKED_REMOTE_IMAGE' => " checked"));
  }
  
  $the_img_src = strstr($img_src, "notfound_image") ? "" : $img_src;
  $tpl->assign(array('THE_IMG_SRC' => $the_img_src));
  
  $tpl->parse('FIELD_REMOTE_IMAGE', 'field_remote_image');
} else {
  $tpl->clear_dynamic('field_remote_image');
}



$tpl->parse('FORM', 'upload_form');
$form = $tpl->fetch('FORM');

$title = "Subir Foto";

if(isset($_SESSION['userid']))
$content .= $image_code;

if(isset($message_code)) $content .= $message_code;

if(isset($_SESSION['userid'])) $content .= $form;

$final_output = table($title, $content);


$tpl->assign(array('CONTENT_TEXT' => $final_output));
$tpl->parse('PAGE', 'main');
$final_output = $tpl->fetch('PAGE');



$final_output = final_output($final_output);

//echo $final_output;
include ("copy.php");

function NewImageAddedNotification($uid, $img)
{
    global $tb_users, $tb_user_types, $dat_base_url, $owner_email, $tb_email_templates;

    $sql = "select u.username, ut.user_type from $tb_users u, $tb_user_types ut where u.id = '$uid' and u.user_type=ut.id ";
    $res = mysql_query($sql);
    echo mysql_error();

    if ($data = mysql_fetch_row($res))
    {
$username = $data[0];
$usertype = $data[1];
    }	

     $mailheader="From: ".$owner_email;
     $mailheader.="\r\nMIME-Version: 1.0\r\n";
     $mailheader.="Content-type: text/html; charset=iso-8859-1\r\n";

     $subject = "Nueva imagen agregada en $dat_base_url ";

    $sql = "select  file_content  from $tb_email_templates  where file_name = 'new_image_notification' ";
    $res = mysql_query($sql);
    echo mysql_error();

    if ($data = mysql_fetch_row($res))
    {
$message = $data[0];	
    }	

    
    $message = ereg_replace("<<BASE_URL>>",$dat_base_url, $message);
    $message = ereg_replace("<<USERNAME>>",$username, $message);
    $message = ereg_replace("<<USERTYPE>>",$usertype, $message);
    $message = ereg_replace("<<IMAGE_SRC>>",$img, $message);


/*
     $message = "New image was added in the site $dat_base_url <br><br>
	<b>User Details :</b> <br><br>
	Username : $username<br>
	Usertype   : $usertype <br><br>
	Image : <img src='$img' border=1 >";

*/


    $to = $owner_email;
    mail($to, $subject, $message, $mailheader);		
}

?>

Link to comment
Share on other sites

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.