2012-06-28 236 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

腳本正在工作......!沒問題!