SYP}{ER
09-25-2002, 01:35 AM
Ok, this is long but pretty straight-forward. The uploading part of the script doesn't work. The images just don't upload. I think it might be my ImageCopyResampledBicubic function (borrowed from the dude who posted it on php.net) or it could be something else. I can't fix it for the life of me :(
if ($entry_form_submitted=="1"):
$required = array (
array ($make,"Make"),
array ($model,"Model"),
array ($year,"Year")
);
if ($action!="edit") $required[] = array ($imagefile,"Image");
for ($i=0;$i<count($required);$i++){
if ($required[$i][0] == ""):
print_error ("You missed the \"{$required[$i][1]}\" field.");
$continue = "no";
endif;
}
// Function used to resize image
function ImageCopyResampleBicubic ($dst_img, $src_img, $dst_x, $dst_y,$src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
/*
for ($i = 0; $i < imagecolorstotal($src_img); $i++){
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);
}
*/
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $src_y + $dst_h; $j++){
$sY = $j * $scaleY;
for ($i = $src_x; $i < $src_x + $dst_w; $i++){
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY));
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = ImageColorClosest ($dst_img, $red, $green,$blue);
ImageSetPixel ($dst_img, $dst_x + $i - $src_x, $dst_y + $j - $src_y,$color);
}
}
}
// Math to find new width and height
if ($imagefile):
$a_size = getimagesize ($imagefile); // 0=width, 1=height
$aw = $a_size[0];
$ah = $a_size[1];
$big_w = 527;
$big_h = round ($ah/($aw/$big_w),0);
$sml_w = 250;
$sml_h = round ($ah/($aw/$sml_w),0);
$supersml_w = 50;
$supersml_h = round ($ah/($aw/$supersml_w),0);
if ($aw > $big_w) $large_is_too_big = true;
$extension = substr ($_FILES['imagefile']['name'],-3);
endif;
if (!$agree):
print_error ("You must agree to the terms before you can enter your vehicle.");
$continue="no";
endif;
if ($continue!="no"):
$make = strtolower ($make);
$model = strtolower ($model);
$body = strip_tags ($body,"<b><i><u>");
// Ensure that the directories exist, and if they don't, make them!
if (!is_dir ("images/gallery/$make")):
mkdir ("images/gallery/$make",0700);
chmod ("images/gallery/$make", 0777);
endif;
clearstatcache();
if (!is_dir ("images/gallery/$make/$model")):
mkdir ("images/gallery/$make/$model",0700);
chmod ("images/gallery/$make/$model", 0777);
endif;
clearstatcache();
if (!is_dir ("images/gallery/$make/$model/$year")):
mkdir ("images/gallery/$make/$model/$year",0700);
chmod ("images/gallery/$make/$model/$year", 0777);
endif;
clearstatcache();
if ($action=="add"):
mysql_query ("INSERT INTO entries (make,model,year,engine,horsepower,torque,zero_to_sixty,net_value,body,author,for_sale) VALUES ('$make','$model','$year','$engine','$horsepower','$torque','$zero_to_sixty','$net_value','$body','".$session_var["user_info"]["username"]."','$for_sale')");
mysql_query ("INSERT INTO menu (make,model,year) VALUES ('$make','$model','$year')");
mysql_query ("UPDATE stats_main SET total_entries=total_entries+1");
mysql_query ("UPDATE members SET entries=entries+1 WHERE username='".$session_var["user_info"]["username"]."'");
$id = mysql_fetch_array (mysql_query ("SELECT id FROM entries WHERE author='".$session_var["user_info"]["username"]."' ORDER BY id DESC"));
$id = $id['id'];
move_uploaded_file ($_FILES["imagefile"]["name"],"images/gallery/$make/$model/$year/$id.jpg");
if ($large_is_too_big):
$filename = "images/gallery/$make/$model/$year/$id.jpg";
$src_img = imagecreatefromjpeg($imagefile);
$dst_img = imagecreatetruecolor($big_w,$big_h);
ImageCopyResampleBicubic ($dst_img, $src_img, 0, 0, 0, 0, $big_w, $big_h, $aw, $ah);
imagejpeg($dst_img, $filename, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
clearstatcache();
endif;
$filename = "images/gallery/$make/$model/$year/$id-t.jpg";
$src_img = imagecreatefromjpeg($imagefile);
$dst_img = imagecreatetruecolor($sml_w,$sml_h);
ImageCopyResampleBicubic ($dst_img, $src_img, 0, 0, 0, 0, $sml_w, $sml_h, $aw, $ah);
imagejpeg($dst_img, $filename, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
$filename = "images/gallery/$make/$model/$year/$id-ts.jpg";
$src_img = imagecreatefromjpeg($imagefile);
$dst_img = imagecreatetruecolor($supersml_w,$supersml_h);
ImageCopyResampleBicubic ($dst_img, $src_img, 0, 0, 0, 0, $supersml_w, $supersml_h, $aw, $ah);
imagejpeg($dst_img, $filename, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
do_confirm ("Your entry has been submitted! Thank you for contributing.","$wereGoingTo");
Thanks a million for ANY help at all. I left out the endif; parts but they don't really matter. Just the image uploading ($imagefile is the file field of the form and is the image file after it's been uploaded. Now the image IS actually uploaded, but for some reason it isn't copied anywhere permenent...)
if ($entry_form_submitted=="1"):
$required = array (
array ($make,"Make"),
array ($model,"Model"),
array ($year,"Year")
);
if ($action!="edit") $required[] = array ($imagefile,"Image");
for ($i=0;$i<count($required);$i++){
if ($required[$i][0] == ""):
print_error ("You missed the \"{$required[$i][1]}\" field.");
$continue = "no";
endif;
}
// Function used to resize image
function ImageCopyResampleBicubic ($dst_img, $src_img, $dst_x, $dst_y,$src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
/*
for ($i = 0; $i < imagecolorstotal($src_img); $i++){
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);
}
*/
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $src_y + $dst_h; $j++){
$sY = $j * $scaleY;
for ($i = $src_x; $i < $src_x + $dst_w; $i++){
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY));
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = ImageColorClosest ($dst_img, $red, $green,$blue);
ImageSetPixel ($dst_img, $dst_x + $i - $src_x, $dst_y + $j - $src_y,$color);
}
}
}
// Math to find new width and height
if ($imagefile):
$a_size = getimagesize ($imagefile); // 0=width, 1=height
$aw = $a_size[0];
$ah = $a_size[1];
$big_w = 527;
$big_h = round ($ah/($aw/$big_w),0);
$sml_w = 250;
$sml_h = round ($ah/($aw/$sml_w),0);
$supersml_w = 50;
$supersml_h = round ($ah/($aw/$supersml_w),0);
if ($aw > $big_w) $large_is_too_big = true;
$extension = substr ($_FILES['imagefile']['name'],-3);
endif;
if (!$agree):
print_error ("You must agree to the terms before you can enter your vehicle.");
$continue="no";
endif;
if ($continue!="no"):
$make = strtolower ($make);
$model = strtolower ($model);
$body = strip_tags ($body,"<b><i><u>");
// Ensure that the directories exist, and if they don't, make them!
if (!is_dir ("images/gallery/$make")):
mkdir ("images/gallery/$make",0700);
chmod ("images/gallery/$make", 0777);
endif;
clearstatcache();
if (!is_dir ("images/gallery/$make/$model")):
mkdir ("images/gallery/$make/$model",0700);
chmod ("images/gallery/$make/$model", 0777);
endif;
clearstatcache();
if (!is_dir ("images/gallery/$make/$model/$year")):
mkdir ("images/gallery/$make/$model/$year",0700);
chmod ("images/gallery/$make/$model/$year", 0777);
endif;
clearstatcache();
if ($action=="add"):
mysql_query ("INSERT INTO entries (make,model,year,engine,horsepower,torque,zero_to_sixty,net_value,body,author,for_sale) VALUES ('$make','$model','$year','$engine','$horsepower','$torque','$zero_to_sixty','$net_value','$body','".$session_var["user_info"]["username"]."','$for_sale')");
mysql_query ("INSERT INTO menu (make,model,year) VALUES ('$make','$model','$year')");
mysql_query ("UPDATE stats_main SET total_entries=total_entries+1");
mysql_query ("UPDATE members SET entries=entries+1 WHERE username='".$session_var["user_info"]["username"]."'");
$id = mysql_fetch_array (mysql_query ("SELECT id FROM entries WHERE author='".$session_var["user_info"]["username"]."' ORDER BY id DESC"));
$id = $id['id'];
move_uploaded_file ($_FILES["imagefile"]["name"],"images/gallery/$make/$model/$year/$id.jpg");
if ($large_is_too_big):
$filename = "images/gallery/$make/$model/$year/$id.jpg";
$src_img = imagecreatefromjpeg($imagefile);
$dst_img = imagecreatetruecolor($big_w,$big_h);
ImageCopyResampleBicubic ($dst_img, $src_img, 0, 0, 0, 0, $big_w, $big_h, $aw, $ah);
imagejpeg($dst_img, $filename, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
clearstatcache();
endif;
$filename = "images/gallery/$make/$model/$year/$id-t.jpg";
$src_img = imagecreatefromjpeg($imagefile);
$dst_img = imagecreatetruecolor($sml_w,$sml_h);
ImageCopyResampleBicubic ($dst_img, $src_img, 0, 0, 0, 0, $sml_w, $sml_h, $aw, $ah);
imagejpeg($dst_img, $filename, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
$filename = "images/gallery/$make/$model/$year/$id-ts.jpg";
$src_img = imagecreatefromjpeg($imagefile);
$dst_img = imagecreatetruecolor($supersml_w,$supersml_h);
ImageCopyResampleBicubic ($dst_img, $src_img, 0, 0, 0, 0, $supersml_w, $supersml_h, $aw, $ah);
imagejpeg($dst_img, $filename, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
do_confirm ("Your entry has been submitted! Thank you for contributing.","$wereGoingTo");
Thanks a million for ANY help at all. I left out the endif; parts but they don't really matter. Just the image uploading ($imagefile is the file field of the form and is the image file after it's been uploaded. Now the image IS actually uploaded, but for some reason it isn't copied anywhere permenent...)