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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?