Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. $conn_id = ftp_connect('***');
  2. $login_result = ftp_login($conn_id, '***','***');
  3. if( $login_result) echo 'connected';
  4. $save = "FTP://temp/". $FileName;
  5.  
  6. imagepng($this->Picture, $save);
  7.  
  8. /*if (ftp_put($conn_id,$save,$save, FTP_ASCII))
  9. echo "successfully uploaded n";
  10. else
  11. echo "There was a problem while uploading n";
  12. */
  13.  
  14. ob_start();
  15. imagepng($this->Picture);
  16. $image = ob_get_clean();
  17. $stream = stream_context_create(array('ftp' => array('overwrite' => true)));
  18. file_put_contents("ftp://user:pass@host/folder/".$FileName, $image, 0, $stream);
  19.  
  20. <?
  21.  
  22. //Configuration
  23. $ftp_server = "ftpaddress";
  24. $ftp_user = "username";
  25. $ftp_pass = "password";
  26.  
  27. // set up a connection or die
  28. $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
  29.  
  30. //trying to connect with login details
  31. if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  32. echo "Connected! ";
  33. } else {
  34. echo "Couldn't connect!";
  35. }
  36.  
  37. //You can change it with the file name, this is for if you're upload using form.
  38.  
  39. $myName = $_POST['name']; //This will copy the text into a variable
  40. $myFile = $_FILES['file_name']; // This will make an array out of the file information that was stored.
  41. ?>
  42.  
  43. <?PHP
  44. $destination_path = "dest/path/";
  45.  
  46. //your desired path for uploading)
  47.  
  48. $destination_file = $destination_path."img.jpg";
  49.  
  50. //This will create a full path with the file on the end for you to use, I like splitting the variables like this in case I need to use on on their own or if I'm dynamically creating new folders.
  51.  
  52. $file = $myFile['tmp_name'];
  53.  
  54. //Converts the array into a new string containing the path name on the server where your file is.
  55.  
  56. $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);// upload the file
  57. if (!$upload) {// check upload status
  58. echo "FTP upload of $destination_file has failed!";
  59. } else {
  60. echo "Uploaded $file to $conn_id as $destination_file";
  61. }
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement