While you can upload files to an FTP server with ftp_put
, that would need a file that you want to upload. What if the contents of a file are inside a MySQL field?
How can I upload a file that lives in a MySQL BLOB field to an FTP server (so upload a file from a string containing file data instead of a file path)? I'm looking for a native solution, not a workaround. This because writing the data to a file, uploading the file, and deleting a file would take too long.
Edit to clarify the OP's question: I have a string variable that I want to upload to an FTP server. The quick and dirty way is to create a physical temporary file from my string variable, upload that file to the FTP server, and then delete the temporary file. But is there a way to upload the string variable directly to the FTP server without having to create a temporary file from it?
Okay, I found a solution.
$fileContent = 'My file contents here';
$contentstream = fopen('data://text/plain,' . $fileContent, 'r');
ftp_fput($myConnection, '/path/to/my/folder/file.txt', $contentStream, FTP_BINARY);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments