2013-01-23 50 views
1

我想移動一個已經使用imagettftext創建並保存爲png的文件。如您所見,在下面的代碼中,我使用了move_uploaded_file,但無濟於事。請幫忙。移動上傳的文件php不工作

TQ

// Set the content-type 
header('Content-Type: image/png'); 



// Create the image from created image 
//$im = imagecreatetruecolor(180, 180); 
$im = @imagecreatefromjpeg('poloroid.jpg'); 

// Create some colors 
$white = imagecolorallocate($im, 255, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0); 
//imagefilledrectangle($im, 0, 0, 399, 29, $white); 

// The text to draw 
//$text = 'John...'; 
$fbid = $_POST["id"]; 
$text = $_POST["want"]; 
$fb_email =$_POST["email"]; 
$fb_name=$_POST["name"]; 

$uploads_dir = '/uploaded_files'; 
// Replace path by your own font path 
$font = 'verdana.ttf'; 

//image file name 
$name ="$fbid.png"; 


// Add some shadow to the text 
imagettftext($im, 20, 0, 25, 126, $grey, $font, $text); 

// Add the text 
imagettftext($im, 20, 0, 25, 125, $black, $font, $text); 

// Using imagepng() results in clearer text compared with imagejpeg() 
//imagepng($im); 
imagepng($im,$name,9); 
move_uploaded_file($name,"$uploads_dir/$name"); 
imagedestroy($im); 
+0

刪除'@'從'imagecreatefromjpeg符號()',看看你得到任何錯誤,還要確保'error_reporting'處於打開狀態。 –

+0

move_uploaded_file只移動通過表單上傳的文件,您應該使用函數[rename](http://php.net/manual/en/function.rename.php) –

回答

5

您還沒有上傳文件,則生成一個!

imagepngfilename參數,所以你可以將它保存到您的驅動器:

$uploads_dir = '/uploaded_files/'; 
$name = $uploads_dir.$fbid.'.png'; 
imagepng($im,$name,9); 
imagedestroy($im); 
+0

好吧。我正在創建一個文件。 imagepng($ im,$ name,9);創建它。所以我怎樣才能將創建的文件傳輸到uploaded_files文件夾中? –

+0

Exacly就像我發佈的那樣,將'$ uploads_dir'添加到'$ name',只要確保'upload_dir'與腳本相關。 –

+0

好吧。現在測試它 –

1

嘗試使用rename代替move_uploaded_file