【问题标题】:Move uploaded file php not working移动上传的文件php不起作用
【发布时间】:2013-01-23 08:58:47
【问题描述】:

我想移动一个使用 imagettftext 创建并保存为 png 的文件。如您所见,在下面的代码中,我使用了 move_uploaded_file 但无济于事。请帮忙。

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

【问题讨论】:

  • imagecreatefromjpeg() 中删除@ 符号,看看是否有任何错误,同时确保error_reporting 处于打开状态。
  • move_uploaded_file 仅移动通过表单上传的文件,您应该使用函数rename

标签: php upload imagettftext


【解决方案1】:

您不是在上传文件,而是在生成一个文件!

imagepng 具有 filename 参数,因此您可以将其保存到驱动器中:

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

【讨论】:

  • 好的。我正在创建一个文件。 imagepng($im,$name,9);创建它。那么如何将创建的文件传输到 upload_files 文件夹中?
  • 就像我发布的一样,将$uploads_dir 添加到$name,只要确保upload_dir 与脚本相关。
  • 在日志中得到这个错误; imagepng() [function.imagepng]:无法打开'/uploaded_files/1279548298.png'
  • uploaded_files 不是有效路径或可写目录。
  • 在uploaded_files 似乎工作之前删除/...非常感谢Mihai Lorga
【解决方案2】:

尝试使用rename 而不是move_uploaded_file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多