0

When I test this code on my computer everything works fine but in prod, the file uploaded on the remote server is empty. What kind of php/server config could cause this issue?

static function implicit_ftp($srcFile, $dstFile, $host, $port = 21, $username = null, $password = null, $acc = null)
    {
        $curlhandle = curl_init();
        curl_reset($curlhandle);
        curl_setopt($curlhandle, CURLOPT_URL, 'ftps://' . $host . '/' . $dstFile);
        curl_setopt($curlhandle, CURLOPT_USERPWD, $username . ':' . $password);
        curl_setopt($curlhandle, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curlhandle, CURLOPT_PORT, $port);
        curl_setopt($curlhandle, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curlhandle, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
        curl_setopt($curlhandle, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);

        $fp = fopen($srcFile, 'r');
        curl_setopt($curlhandle, CURLOPT_UPLOAD, 1);
        curl_setopt($curlhandle, CURLOPT_INFILESIZE, filesize($srcFile));
        curl_setopt($curlhandle, CURLOPT_INFILE, $fp);

        curl_exec($curlhandle);
        $err = curl_error($curlhandle);
    }
user2942945
  • 469
  • 1
  • 7
  • 19

1 Answers1

0

First double-check if the php extension curl is running. For that, simply create an info.php file and Insert the following: phpinfo(). Visit the website and use CTRL+F and search for curl.

If curl is enabled, you could be facing a permission issue. Since I don't know what type of web-server you are using, I am just going to assume that it is Apache for now. You will need write and read permissions. To set these up, have a look at the following thread: Apache Give Permission

Since I can see a ftp tag in your thread, you can also use an ftp client to simply right click the folder in which you want to insert your image and go to permissions to apply them from there.

xyba
  • 17
  • 6
  • yes, Curl is installed, we use it everywhere. this is the file generated on the server -rw-r--r-- 1 apache apache 7219 Nov 15 09:44 VVQ-LYNX548332_15-11-2022_094419.xml – user2942945 Nov 15 '22 at 15:14
  • The file appears not to be empty by what you have provided. what is the contents using `less` command or `cat` command? Example: `less VVQ-LYNX548332_15-11-2022_094419.xml` – Pavel Janicek Nov 15 '22 at 15:17
  • sorry, I mean, this is the file I am trying to upload. I wanted to show you the permission. – user2942945 Nov 15 '22 at 15:19
  • Then it does not matter what permission has the file. The target directory also has to have access pernission – Pavel Janicek Nov 15 '22 at 15:20