Php 将服务器创建的映像上载到FTP服务器
我一遍又一遍地读我的代码,但我不知道是什么地方出了问题 脚本:Php 将服务器创建的映像上载到FTP服务器,php,image,ftp,pdo,jpeg,Php,Image,Ftp,Pdo,Jpeg,我一遍又一遍地读我的代码,但我不知道是什么地方出了问题 脚本: <? require_once("../constant/constant.php"); if($_POST['action'] == 'imgsave'){ $admin = $_POST['admin']; $profile = $_POST['profile']; $sth = $conn->prepare("SELECT * FROM profiles WHER
<?
require_once("../constant/constant.php");
if($_POST['action'] == 'imgsave'){
$admin = $_POST['admin'];
$profile = $_POST['profile'];
$sth = $conn->prepare("SELECT * FROM profiles WHERE profile_id = '".$profile."'");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
$targ_w = 180;
$targ_h = 120;
$src = imagecreatefromjpeg('../uploads/'.$profile.'.jpg');
$tmp = imagecreatetruecolor($targ_w, $targ_h);
imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
//Grab new image
ob_start();
imagejpeg($tmp);
$image = ob_get_contents();
ob_end_clean();
imagedestroy($tmp);
imagedestroy($src);
//Create temporary file and write to it
$fp = tmpfile();
fwrite($fp, $image);
rewind($fp);
//Upload new image
$conn_id = ftp_connect('ftp.test.com');
ftp_login($conn_id,'user','pass');
ftp_fput($conn_id,'/profiles/'.$row['path'].'/preview2.jpg', $fp, FTP_BINARY);
fclose($fp);
}
?>
如您所见,原始脚本非常简单。。我想我被困在了它变得多么先进。。任何人都可以看到解决方案,或者给我一个关于其他操作的提示。脚本正在运行。。。!没问题 你收到了什么错误/警告/通知?从ob_get_clean手册页面:ob_get_clean实际上执行ob_get_内容和ob_end_clean。我现在感觉很愚蠢。。脚本是100%的工作。。。我只是不需要在常量前面加“../”。。。
$src = imagecreatefromjpeg($folder.$filename);
$tmp = imagecreatetruecolor($targ_w, $targ_h);
imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
imagejpeg($tmp, $folder.'t_'.$filename,100);
imagedestroy($tmp);
imagedestroy($src);