dou12352 2010-04-29 09:32
浏览 35
已采纳

php上传图片与ftp问题

I am using the code below to upload an image through ftp

$sFile=$ftp_dir."/".$image_name;

$image=$database_row["image"];//image is store in database

$fh = tmpfile();
$fwrite($fh, $image);

$uploadFile = ftp_fput($conn_id, $sFile, $fh, FTP_ASCII); 

fclose($fh);

The ftp is creating the file and has a size BUT the file i get is not an image.When try to open on image viewer i get error.

Before switch to ftp i had this code

$image=$database_row["image"];//image is store in database
   $file = fopen( "images/".$image_name, "w" );
   fwrite( $file, $image);
   fclose( $file );

and was working fine, but now i have to use ftp.

What am i missing.

  • 写回答

4条回答 默认 最新

  • dousao8152 2010-04-29 09:44
    关注

    You need to fseek to the beginning of the file after writing content to it and you need to use binary upload mode:

    $sFile=$ftp_dir."/".$image_name;
    $image=$database_row["image"];//image is store in database
    $fwrite($fh, $image);
    fseek($fh, 0);
    $uploadFile = ftp_fput($conn_id, $sFile, $fh, FTP_BINARY); 
    fclose($fh);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突