1

I'm trying to upload a variable into a json file on my server todo so I use PHP to make connection and login to the FTP server. This is the code I use:

<?php
    $ftp_server = $_POST["ftp_server"];
    $database_url = $_POST["database_url"];
    $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
    $login = ftp_login($ftp_conn, $_POST["username"], $_POST["password"]);

    $file = fopen('php://temp', 'r+');
    fwrite($file, $_POST["pass_json"]);

    if (ftp_nb_put($ftp_conn, $database_url, $file, FTP_ASCII)){
      echo "Successfully uploaded $file.";
    } else {
      echo "Failed to upload $file.";
    }
    rewind($file);
    ftp_close($ftp_conn);
?>

The connection is valid ($ftp_conn). the login is valid as well ($login).

$_POST["pass_json"] is the correct information and $_POST["database_url"] is the url you fill in your webbrowser to look at the json file in your webbrowser. this is being done with a SSL certificate in https to protect the username and password given. What am I doing wrong?

j08691
  • 204,283
  • 31
  • 260
  • 272
NoahS
  • 21
  • 1
  • 6
  • Just wondering dont you have to close the file first before uploading? – Chopnut Nov 21 '18 at 20:06
  • Now you came up with I should but, when I tried just now again while it's been closed it still fails to upload. `fclose($file)` – NoahS Nov 21 '18 at 20:12

0 Answers0