dongnao3990
2017-06-23 07:38
浏览 63
已采纳

如何将文件名传递给ftp_put函数?

It's a simple code to resize an image and send it to ftp server:

$info = getimagesize($_FILES["personalPhoto"]["tmp_name"]);
$image = imagecreatefromjpeg($_FILES["personalPhoto"]["tmp_name"]);
ob_start();
imagejpeg($image,null, 1);
$resizedImage = ob_get_contents();
ob_end_clean();   


ftp_put($ftpConn,'/Kamil/HostMe/AllImages/'.$fileName.'.jpg',$_FILES["personalPhoto"]["tmp_name"],FTP_BINARY);

ftp_put($ftpConn,'/Kamil/HostMe/AllImages/'.$fileName.'.jpg',$resizedImage,FTP_BINARY);

The first ftp_put command works fine (sends the original image to server)

the second ftp_put command which is supposed to send the resized image is not working. any ideas?

图片转代码服务由CSDN问答提供 功能建议

这是一个简单的代码来调整图像大小并将其发送到ftp服务器: < pre> $ info = getimagesize($ _ FILES [“personalPhoto”] [“tmp_name”]); $ image = imagecreatefromjpeg($ _ FILES [“personalPhoto”] [“tmp_name”]); ob_start(); imagejpeg($ image,null,1); $ resizedImage = ob_get_contents(); ob_end_clean(); ftp_put($ ftpConn, '/卡米尔/ HostMe / AllImages /'.$文件名。' JPG”,$ _ FILES [ “personalPhoto”] [ “tmp_name的值”],FTP_BINARY); ftp_put($ ftpConn,'/ Kamil / HostMe / AllImages /'.$ fileName。'。jpg',$ resizedImage,FTP_BINARY);

第一个ftp_put命令工作正常( 将原始图像发送到服务器)

第二个ftp_put命令应该发送调整大小的图像不起作用。 任何想法?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzanxun2790 2017-06-23 07:45
    已采纳

    $resizedImage is a PHP variable, not a physical file. To solve your problem, you can write $resizedImage into a file then set this to ftp_put. Such as:

    $file = "/tmp/somefile.jpg";
    file_put_contents($file, $resizedImage);
    ftp_put(
      $ftpConn,
      '/Kamil/HostMe/AllImages/'.$fileName.'.jpg',
      $file,
      FTP_BINARY
    );
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题