Jump to content

image resize problem


garydt

Recommended Posts

ok, i did those changes and i got

Notice: Undefined index: MM_Username in C:\Program Files\xampp\htdocs\epeople\uploadforom3.php on line 58

 

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\epeople\uploadforom3.php:58) in C:\Program Files\xampp\htdocs\epeople\uploadforom3.php on line 65

<?php require_once('Connections/elvisdb.php'); ?>
<?php
session_start();
error_reporting(E_ALL);
$editFormAction = '';
$max_file_size = 1024*1024*1024; //1MB

if(isset($_POST['sent'])){
unset($submit);
if (isset($_POST['sent'])) $submit = true;
else die('Error: No file got sent');

$fieldname = 'file';
function resizeimage($name){
$filename = './uploads/'.$name['name'];
	if(file_exists($filename)) {
		$image		= imagecreatefromjpeg($filename); //unresized image
		$im_info	= getimagesize($filename); //unresized image
		$im_width	= $im_info[0];
		$im_height	= $im_info[1];
		$im_flag	= $im_info[2];

		//max height: 100px; max width: 100px
		if($im_width >= $im_height) {
			$im_divice	= $im_width / 100;
		}else {
			$im_divice	= $im_height / 100;
		}
		$thumb_width	= $im_width / $im_divice;
		$thumb_height	= $im_height / $im_divice;

		//create empty image
		$thumb	= imagecreatetruecolor($thumb_width, $thumb_height);
		//resize image
		imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height);

		if(imagejpeg($thumb, "thumbnails/".$newimage, 80)) { //image-resource, filename, quality
			return 1;
		}

		imagedestroy($thumb); //destroy temporary image-resource
		imagedestroy($image); //destroy temporary image-resource
	}
}

// make a note of the directory that will recieve the uploaded file 
// full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; 
$uploadsDirectory = './uploads/'; 

//Upload image
$uploadFilename = $uploadsDirectory.$fieldname['name'];

// now let's move the file to its final location and allocate the new filename to it 
move_uploaded_file($fieldname['tmp_name'], $uploadFilename);

resizeimage($fieldname['name']);

$user = $_SESSION['MM_Username'];


mysql_select_db($database_elvisdb, $elvisdb);
$insertSQL = sprintf("INSERT INTO images (imageName, usnm) VALUES ('$uploadFilename', '$user')");

  $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error());
  header("Location: userpage.php");
}

?>
<!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>Untitled Document</title>
</head>

<body>
<form name="form1" id="Upload" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="POST"> 
     
        <h1> 
            Upload form 
        </h1> 
         
        <p> 
            <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> 
        </p> 
         
        <p> 
            <label for="file">File to upload:</label> 
            <input id="file" type="file" name="file"> 
        </p>
        <p>
          <label>
          <input name="sent" type="hidden" id="sent" value="1" />
          </label>
        </p>
        <p> 
            <label for="submit">Press to...</label> 
            <input id="submit" type="submit" name="submit" value="Upload me!"> 
        </p> 
     
        <input type="hidden" name="MM_insert" value="form1">
</form> 
</body>
</html>

Link to comment
Share on other sites

pardon... i didn't change $fieldname:

<?php require_once('Connections/elvisdb.php'); ?>
<?php
session_start();
error_reporting(E_ALL);
$editFormAction = '';
$max_file_size = 1024*1024*1024; //1MB

if(isset($_POST['sent'])){
unset($submit);
if (isset($_POST['sent'])) $submit = true;
else die('Error: No file got sent');

$fieldname = 'file';
function resizeimage($name){
$filename = './uploads/'.$name['name'];
	if(file_exists($filename)) {
		$image		= imagecreatefromjpeg($filename); //unresized image
		$im_info	= getimagesize($filename); //unresized image
		$im_width	= $im_info[0];
		$im_height	= $im_info[1];
		$im_flag	= $im_info[2];

		//max height: 100px; max width: 100px
		if($im_width >= $im_height) {
			$im_divice	= $im_width / 100;
		}else {
			$im_divice	= $im_height / 100;
		}
		$thumb_width	= $im_width / $im_divice;
		$thumb_height	= $im_height / $im_divice;

		//create empty image
		$thumb	= imagecreatetruecolor($thumb_width, $thumb_height);
		//resize image
		imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height);

		if(imagejpeg($thumb, "thumbnails/".$newimage, 80)) { //image-resource, filename, quality
			return 1;
		}

		imagedestroy($thumb); //destroy temporary image-resource
		imagedestroy($image); //destroy temporary image-resource
	}
}

// make a note of the directory that will recieve the uploaded file 
// full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; 
$uploadsDirectory = './uploads/'; 

//Upload image
$uploadFilename = $uploadsDirectory.$fieldname['name'];

// now let's move the file to its final location and allocate the new filename to it 
move_uploaded_file($fieldname['tmp_name'], $uploadFilename);

resizeimage($fieldname['name']);

$user = $_SESSION['MM_Username'];


mysql_select_db($database_elvisdb, $elvisdb);
$insertSQL = sprintf("INSERT INTO images (imageName, usnm) VALUES ('$uploadFilename', '$user')");

  $Result1 = mysql_query($insertSQL, $elvisdb) or die(mysql_error());
  header("Location: userpage.php");
}

?>
<!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>Untitled Document</title>
</head>

<body>
<form name="form1" id="Upload" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="POST"> 
     
        <h1> 
            Upload form 
        </h1> 
         
        <p> 
            <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> 
        </p> 
         
        <p> 
            <label for="file">File to upload:</label> 
            <input id="file" type="file" name="file"> 
        </p>
        <p>
          <label>
          <input name="sent" type="hidden" id="sent" value="1" />
          </label>
        </p>
        <p> 
            <label for="submit">Press to...</label> 
            <input id="submit" type="submit" name="submit" value="Upload me!"> 
        </p> 
     
        <input type="hidden" name="MM_insert" value="form1">
</form> 
</body>
</html>

Link to comment
Share on other sites

Ah! I see!

just replace

$filename = './uploads/'.$name['name'];

into

$filename = './uploads/'.$name;

(after resizeimage($name){)

Because we already call the function with the filename.

So... what's $newimage? It's undefined. I didn't put it into the code.

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.