Shazery Nasir
Shazery Nasir

Reputation: 281

Move uploaded file php not working

I want to move a file that has been created using imagettftext and saved as a png. as you can see, in the code below, i used the move_uploaded_file but to no avail. please help.

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

Upvotes: 1

Views: 991

Answers (2)

Karim
Karim

Reputation: 2638

try to use rename instead of move_uploaded_file

Upvotes: 1

Mihai Iorga
Mihai Iorga

Reputation: 39724

You are not uploading a file, you are generating one!

imagepng has filename parameter so you can save it to your drive:

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

Upvotes: 5

Related Questions