Creating and uploading a file in PHP to an FTP server without saving locally

前端 未结 4 1633
感动是毒
感动是毒 2020-12-08 23:55

I\'m having a problem connecting two different processes that I have working. I\'ve been tasked with pulling data out of a database, creating a file from the data, and then

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 00:33

    Actually ftp_put expects the path to the local file (as a string), so try to write the data in a temporary file and then ftp_put it to the server

    
    file_put_contents('/tmp/filecontent'.session_id(), $out);
    ftp_put($ftp_conn, $remote_file_name, '/tmp/filecontent'.session_id());
    unlink('/tmp/filecontent'.session_id()); 
    
    

    In this case you don't need to send the headers you were sending in your example.

提交回复
热议问题