Jump to content

thumb script help please (low priority)


fantomel

Recommended Posts

Hello i`ve build a small upload form with a thumbnail script in it but doesn't work and i don't know why :( can someone check it out please?

upload.php

<?php
session_start();
if (!$_SESSION['rows']) $_SESSION['rows']=1;
?>
<form action="do_upload.php" method="post" enctype="multipart/form-data" name="form" id="form">
<table width="800" border="1" align="center" cellpadding="3" cellspacing="2" bordercolor="#999999">
<?php
for ($i=1; $i<=$_SESSION['rows']; $i++) {
?>
  <tr>
    <td bgcolor="#D6D6D6">Poza <?=$i;?>:</td>
    <td bgcolor="#D6D6D6"><input name="pic<?=$i;?>" type="file" id="pic<?=$i;?>"  /></td>
  </tr>
<?php } ?>
  <tr>
    <td width="150" bgcolor="#D6D6D6"><input name="Rows" type="submit" class="buton" id="Rows" value="+" />
      <input name="Rows" type="submit" class="buton" id="Rows" value="-" /></td>
    <td width="650" bgcolor="#D6D6D6"><input name="Upload" type="submit" class="buton" id="Upload" value="Upload" /></td>
  </tr>
</table>

</form>


 

do_upload.php
<?php
session_start();
if ($_POST['Rows']) {
if ($_POST['Rows']=="+") $_SESSION['rows']++;
if ($_POST['Rows']=="-") $_SESSION['rows']--;
header("Location: upload.php");
exit;
}


if ($_POST['Upload']=="Upload") {
for ($z=1; $z<=$_SESSION['rows']; $z++) {
	$curent="pic$z";
	if ($_FILES[$curent]['name']!="") {
		$new_name="image_".md5(date("U"));
		$new_name_small="$new_name"."_thumbs.jpg";
		$thumb_size=250;
		list($width, $height, $type) = getimagesize($_FILES[$curent]['tmp_name']);
		$type = image_type_to_extension($type);
		$img_file = "$new_name".".jpg";
		$upload_file = $img_file.basename($_FILES[$curent]['$new_name']);
		move_uploaded_file($_FILES[$curent]['tmp_name'], $upload_file);

		$img_ratio=$width/$height;
		if ($img_ratio>1){
		 $new_width = ($thumb_size<$width)?$thumb_size:$width;
		 $new_height =$new_width/$img_ratio;
		}else{
		 $new_height = ($thumb_size<$width)?$thumb_size:$height;
		 $new_width = $new_height*$img_ratio;
		 }

		if ($type==".jpeg") $source = imagecreatefromjpeg($upload_file); 
		if ($type==".png") $source = imagecreatefrompng($upload_file); 
		if ($type==".gif") $source = imagecreatefromgif($upload_file); 
		$thumb = imagecreatetruecolor($new_width, $new_height);
		imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
		imagejpeg($thumb, "$new_name_small" , 100);
		$poze.="$new_name, ";
	}
	sleep(1);
}
}
?>

 

 

Link to comment
Share on other sites

You say it is not working. What aspect is not working? The file upload? The thumb generation? Single or multiple uploads/thumbnails?

 

sorry i`m just in hurry and i`m mad cuz it's not working forgot to tell what and how.. yes single // multiple upload // thumbail generation doesn't work and i get zip no error :( i don't know why ~X(

Link to comment
Share on other sites

add this to upload.php

session_start();
error_reporting(E_ALL);

 

Notice: Undefined index: rows in C:\x\xampp\htdocs\test\upload.php on line 4

and for do_upload.php

Notice: Undefined index: Rows in C:\x\xampp\htdocs\test\do_upload.php on line 5

Notice: Undefined index: pic1 in C:\x\xampp\htdocs\test\do_upload.php on line 16

Link to comment
Share on other sites

<?php
session_start();
if (isset($_POST['Rows'])) {
      if ($_POST['Rows']=="+") $_SESSION['rows']++;
      if ($_POST['Rows']=="-") $_SESSION['rows']--;
      header("Location: upload.php");
      exit;
}
if (isset($_POST['Upload']) || $_POST['Upload']=="Upload") {
for ($z=1; $z<=$_SESSION['rows']; $z++) {
	$curent="pic$z";
	if (isset($_FILES[$curent]['name']) || $_FILES[$curent]['name']!="") {
		$new_name="image_".md5(date("U"));
		$new_name_small="$new_name"."_thumbs.jpg";
		$thumb_size=250;
		list($width, $height, $type) = getimagesize($_FILES[$curent]['tmp_name']);
		$type = image_type_to_extension($type);
		$img_file = "$new_name".".jpg";
		$upload_file = $img_file.basename($_FILES[$curent]['$new_name']);
		move_uploaded_file($_FILES[$curent]['tmp_name'], $upload_file);
		$img_ratio=$width/$height;
		if ($img_ratio>1){
			$new_width = ($thumb_size<$width)?$thumb_size:$width;
			$new_height =$new_width/$img_ratio;
		}else{
			$new_height = ($thumb_size<$width)?$thumb_size:$height;
			$new_width = $new_height*$img_ratio;
		}	
		if ($type==".jpeg") $source = imagecreatefromjpeg($upload_file); 
		if ($type==".png") $source = imagecreatefrompng($upload_file);	
		if ($type==".gif") $source = imagecreatefromgif($upload_file); 
		$thumb = imagecreatetruecolor($new_width, $new_height); 
		imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
		imagejpeg($thumb, "$new_name_small" , 100);
		$poze.="$new_name, ";
	}
	sleep(1);
}
}
if(isset($poze)){
echo $poze;
}
?>

 

then of course, check the folder to see if it did actually upload.

Link to comment
Share on other sites

<?php
session_start();
if (isset($_POST['Rows'])) {
      if ($_POST['Rows']=="+") $_SESSION['rows']++;
      if ($_POST['Rows']=="-") $_SESSION['rows']--;
      header("Location: upload.php");
      exit;
}
if (isset($_POST['Upload']) || $_POST['Upload']=="Upload") {
for ($z=1; $z<=$_SESSION['rows']; $z++) {
	$curent="pic$z";
	if (isset($_FILES[$curent]['name']) || $_FILES[$curent]['name']!="") {
		$new_name="image_".md5(date("U"));
		$new_name_small="$new_name"."_thumbs.jpg";
		$thumb_size=250;
		list($width, $height, $type) = getimagesize($_FILES[$curent]['tmp_name']);
		$type = image_type_to_extension($type);
		$img_file = "$new_name".".jpg";
		$upload_file = $img_file.basename($_FILES[$curent]['$new_name']);
		move_uploaded_file($_FILES[$curent]['tmp_name'], $upload_file);
		$img_ratio=$width/$height;
		if ($img_ratio>1){
			$new_width = ($thumb_size<$width)?$thumb_size:$width;
			$new_height =$new_width/$img_ratio;
		}else{
			$new_height = ($thumb_size<$width)?$thumb_size:$height;
			$new_width = $new_height*$img_ratio;
		}	
		if ($type==".jpeg") $source = imagecreatefromjpeg($upload_file); 
		if ($type==".png") $source = imagecreatefrompng($upload_file);	
		if ($type==".gif") $source = imagecreatefromgif($upload_file); 
		$thumb = imagecreatetruecolor($new_width, $new_height); 
		imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
		imagejpeg($thumb, "$new_name_small" , 100);
		$poze.="$new_name, ";
	}
	sleep(1);
}
}
if(isset($poze)){
echo $poze;
}
?>

 

then of course, check the folder to see if it did actually upload.

 

still didn't work :|

Link to comment
Share on other sites

I think there is something wrong around here:

 

$img_file = "$new_name".".jpg";

$upload_file = $img_file.basename($_FILES[$curent]['$new_name']);

 

Whether it be the that $upload_file will equal something like "something.jpgthensomemorestuff"

and/or that $new_name is in single quotes

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.