MattLav Posted April 5, 2022 Share Posted April 5, 2022 Hi all, I'm trying to upload an image to an FTP after sending it as a byte array. I am sending the image from UE4 using REST: but I have no understanding of PHP so am struggling with processing the image to in-turn upload it. I have tried searching the forums and the results I have found seem to be defining the path to a local image and uploading that directly, but in this case I don't have a path to an image, just the byte array. Because I have such little understanding of PHP, i'm struggling to discover how to access the actual data being sent and therefore even debug if it is sent correctly. <?php $ftp_server="1.1.1.1"; $ftp_user_name="username"; $ftp_user_pass='password123'; $remote_file = "/uploads/temp.jpg"; //my attempt at converting the byte array to an image $binary=base64_decode($base); // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); file_put_contents($filePath, $binary); // upload a file if (ftp_put($conn_id, $remote_file, $filePath, FTP_ASCII)) { echo "successfully uploaded $file\n"; exit; } else { echo "There was a problem while uploading $fileName\n"; exit; } // close the connection ftp_close($conn_id); ?> Any help would be much appreciated, Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/314667-uploading-an-image-sent-as-byte-array-to-ftp/ Share on other sites More sharing options...
ginerjm Posted April 5, 2022 Share Posted April 5, 2022 Can I ask why you are converting an "image" ( a picture/photo/piece of art that is a jpg,tiff,mpg, etc. file) ) to some kind of array in order to upload it using an ftp process? I would think that you would do that to the image once you got it uploaded where you could write a script to do what it is you are doing. Quote Link to comment https://forums.phpfreaks.com/topic/314667-uploading-an-image-sent-as-byte-array-to-ftp/#findComment-1594983 Share on other sites More sharing options...
requinix Posted April 5, 2022 Share Posted April 5, 2022 FTP doesn't do transfers like that. Use a temporary file like your code is already doing (but remember to delete it afterwards); get the temporary file name with tempnam. Quote Link to comment https://forums.phpfreaks.com/topic/314667-uploading-an-image-sent-as-byte-array-to-ftp/#findComment-1595036 Share on other sites More sharing options...
gizmola Posted April 13, 2022 Share Posted April 13, 2022 Maybe this doesn't matter to you either, but ftp has absolutely no transit/network level security. There is a longstanding php library (phpseclib) that implements ssh/sftp https://github.com/phpseclib/phpseclib. There are also php extensions that do the same. Quote Link to comment https://forums.phpfreaks.com/topic/314667-uploading-an-image-sent-as-byte-array-to-ftp/#findComment-1595311 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.