2012-06-28 66 views
0

我一次又一次地读我的代码,但我无法弄清楚什么是错的..上传服务器创建的映像到FTP服务器上

脚本:

<? 
    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); 

    } 
    ?> 

它与组合jCrop脚本,所有我想是修改原来的脚本将其发布到FTP ..

$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); 

正如你所看到的,原来的剧本是很简单..我想我被困在如何先进的IT成为..任何人都可以看到解决方案或者给我一个暗示还有什么可以做的。

+0

你会得到什么错误/警告/通知?来自ob_get_clean手册页的 – Leri

+0

:“ob_get_clean()实质上执行ob_get_contents()和ob_end_clean()。” –

+0

我现在感觉非常愚蠢......脚本100%工作......我只是不需要在常量前加'../'...... – Dimser

回答

0

脚本正在工作......!没问题!