我在调试旧网站时遇到了一些问题。原来的程序员很长时间没有联系,我似乎无法找到错误。问题似乎是当用户上传图像时,它永远不会进入ftp目录。进行描述,文件名等的数据库值。证书已知并且经过测试。
我做了一些寻找,发现了一些做同样事情的脚本;并且看起来PHP函数仍然有效(在php.net上搜索它们)。所以我有点失落。
这个脚本两个月前就停止了工作。服务器有一些DNS问题,但它已经解决,一切似乎都很好。不确定它是否相关。
如果有人能发现问题,我会非常感激!
<?php
IF($ResizeAuth != "yes" OR $ItemID2Resize == "") //This page will exit right here unless the Resize Authorization is set to yes, and the New Image variable has some value
{
exit();
}
ini_set("memory_limit","24M"); //sets the total memory limit to 24 Megabytes just on this page for all of its scripts. The default is only 8M and fails with re-sizing large images.
$connection = mysql_connect("localhost","dbuser-correct","dbpw-correct");
$db = mysql_select_db("databasename-correct",$connection);
$conn_id = ftp_connect("www.correct-domain.com");
ftp_login($conn_id, "workingftpusername", "workingftppassword") or die("Could not connect");
FUNCTION uploadPic($src_img,$dDir,$maxWidth,$maxHeight,$resizeFlag,$tempName)
{
//destination
//(old) $dest = $dDir.$tempName;
//get source dimentions
$src_dims = getImageSize($src_img);
//create appropriate temp image
switch ($src_dims[2]) {
case 1: //GIF
break;
case 2: //JPEG
$srcImage = imageCreateFromJpeg($src_img);
break;
case 3: //PNG
break;
default:
return false;
break;
}
$srcRatio = $src_dims[0]/$src_dims[1]; // width/height ratio
$destRatio = $maxWidth/$maxHeight;
if ($destRatio > $srcRatio) {
$destSize[1] = $maxHeight;
$destSize[0] = $maxHeight*$srcRatio;
}
else {
$destSize[0] = $maxWidth;
$destSize[1] = $maxWidth/$srcRatio;
}
//if set image dimensions are required:
if ($resizeFlag == 1) {
$destSize[0] = $maxWidth;
$destSize[1] = $maxHeight;
}
$thumb_w = $destSize[0];
$thumb_h = $destSize[1];
$dst_img = imageCreateTrueColor($thumb_w,$thumb_h);
imageCopyResampled($dst_img,$srcImage,0,0,0,0,$thumb_w,$thumb_h,$src_dims[0],$src_dims[1]);
switch ($src_dims[2]) {
case 1:
break;
case 2:
#(original) imageJpeg($dst_img, $dest, 75); //75 denotes image quality / compression ratio
$resizedimage = imageJpeg($dst_img, NULL, 75); //75 denotes image quality / compression ratio
break;
case 3:
break;
}
//$y++;
unlink($src_img);
return $resizedimage;
}
######################
$maxImageWidth = 640; //pixels
$maxThumbWidth = 131; //pixels
$ImageName = $ItemID2Resize."_temp1.jpg";
$ThumbName = $ItemID2Resize."_temp2.jpg";
$NewImageName = "Item".$ItemID2Resize.".jpg";
$NewThumbName = "Item".$ItemID2Resize."_thumb.jpg";
$TempImageFile = uploadPic("temp_image_resize/$ImageName","",$maxImageWidth,0,0,"");
$TempImageFile = fopen($TempImageFile,"r");
@ftp_delete($conn_id, "httpdocs/images/Items/$NewImageName"); //deletes the previous jpg referencing the same item if it exsists.
ftp_fput($conn_id, "httpdocs/images/Items/$NewImageName", $TempImageFile, FTP_BINARY);
fclose($TempImageFile);
#ftp_delete($conn_id, "httpdocs/mckadmin/temp_image_resize/$NewImageName");
$TempThumbFile = tmpfile();
uploadPic("temp_image_resize/$ThumbName","",$maxThumbWidth,0,0,$TempThumbFile);
fseek($TempThumbFile,0);
@ftp_delete($conn_id, "httpdocs/images/Items/$NewThumbName"); //deletes the previous jpg referencing the same item if it exsists.
ftp_fput($conn_id, "httpdocs/images/Items/$NewThumbName", $TempThumbFile, FTP_BINARY);
fclose($TempThumbFile);
#ftp_delete($conn_id, "httpdocs/mckadmin/temp_image_resize/$NewThumbName");
######################
$ImagePath4SQL = "http://www.mycopperkettle.com/images/Items/$NewImageName";
$ThumbPath4SQL = "http://www.mycopperkettle.com/images/Items/$NewThumbName";
$CheckExsistingq = mysql_query("SELECT * FROM Product_ImagePaths WHERE ItemID=\"$ItemID2Resize\"");
$CheckExsisting = mysql_num_rows($CheckExsistingq);
IF($CheckExsisting == 0)
{
mysql_query("INSERT INTO Product_ImagePaths (ItemID,ImagePath,ThumbPath) VALUES (\"$ItemID2Resize\",\"$ImagePath4SQL\",\"$ThumbPath4SQL\")");
}
ELSE
{
mysql_query("UPDATE Product_ImagePaths SET ImagePath=\"$ImagePath4SQL\", ThumbPath=\"$ThumbPath4SQL\" WHERE ItemID=\"$ItemID2Resize\"");
}
ftp_close($conn_id); //close the FTP connection
?>
再次感谢!
~Peril博士