Jump to content

Recommended Posts

I'm trying to upload, resize and create a thumbnail for a picture, at the same time, I introduce some info about it in a database.

The problem is that nothing happens when I execute the form, not even an error message.

Any hints?

<?
$msg = "";
switch(!strcasecmp($_SERVER['REQUEST_METHOD'], "POST")) {

   case true:

if(!isset($_FILES['image']) || $_FILES['image'] == "none" || $_FILES['image'] == "") {
	$msg = "<span class=\"Estyle3\">Select a picture from your PC</span>";
	break;
}
$conn = mysql_connect("","",""); 
mysql_select_db("",$conn);
$sql = "INSERT INTO pictures (desc, refoto) ";
$sql .= "VALUES ('$desc', '$refoto')";
$result = mysql_query($sql) or die(mysql_errno().'<p>'.$sql.'</p>'.mysql_error());

$tmp = getcwd()."/".$_FILES['image']['name'];

if(!@move_uploaded_file($_FILES['image']['tmp_name'], $tmp)) {

	$msg = "<span class=\"Style3\">There was a problem uploading your picture</span>";
	break;
}

$fp = fopen($tmp, "rb");
$str = fread($fp, filesize($tmp));

fclose($fp);
unlink($tmp);

$im1 = ImageCreateFromString($str);

$imgname = $refoto."thumb_1";
$maxwidth = 300;	
$maxheight = 150;	
$width1 = ImageSX($im1);
$height1 = ImageSY($im1);
$width2 = $maxwidth;
$height2 = floor(($width2 * $height1) / $width1);

if($maxheight > 0 && $height2 > $maxheight) {

	$height2 = $maxheight;
	$width2 = floor(($height2 * $width1) / $height1);
}

$im2 = ImageCreateTrueColor($width2, $height2);
ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1);

ImageJpeg($im2, "fotos/thumb/".$imgname.".jpg");	
$msg = "Ok";
$im3 = ImageCreateFromString($str);

$imgname2 = $refoto."_1";	
$maxwidth2 = 800;		
$maxheight2 = 250;	

$width12 = ImageSX($im3);
$height12 = ImageSY($im3);
$width22 = $maxwidth2;
$height22 = floor(($width22 * $height12) / $width12);

if($maxheight2 > 0 && $height22 > $maxheight2) {

	$height22 = $maxheight2;
	$width22 = floor(($height22 * $width12) / $height12);
}

$im4 = ImageCreateTrueColor($width22, $height22);
ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12);

ImageJpeg($im4, "fotos/full/".$imgname2.".jpg");			
break;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<link rel=stylesheet href="thestyle.css" type="text/css">
</head>

<body>
<form id="form1" name="form1" method="post">
    <input type="file" name="image" size="20">
    <input type="hidden" name="value" value="a">
    <input type="hidden" name="refoto" value="b45546">
    
    <br />
    Picture description(20 caracteres) <br />
  
  <label>
  <input name="desc" type="text" id="desc" size="20" maxlength="20" />
  </label>
  <label>
  <input type="submit" name="Submit" value="SEND" />
  </label>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/86439-problem-uploading-picture/
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.