Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a great example on <a href="http://www.php.net/manual/en/ftp.examples-basic.php" rel="nofollow">how to do FTP transfers in PHP</a>. As far as downloading the file, you could use <code>wget</code> if you're on linux (using the <code>exec()</code> function).</p> <pre><code>exec('wget -q ' . $url . ' -0 /path/to/newfile'); </code></pre> <p>Stealing a code snippet from that link I gave you, here is what your function might look like:</p> <pre><code>function downloadImageFromURLAndUploadFTP($image) { // in your case it would be some img extension like .jpg, .gif, or .png // you can check the extension of $image and use that if you want. $newFile = '/path/to/newfile.ext'; exec('wget -q ' . $image . ' -0 ' . $newFile); if (file_exists($newFile)) { // set up connection and login $connect = ftp_connect($ftpServer); $login = ftp_login($connect, $ftpUser, $ftpPass); // check connection if (!$connect || !$login) { die('FTP connection has failed!'); } else { echo "Connected to {$ftpServer}, for user {$ftpUser}"; } // upload the file $fileNameOnFTPServer = 'whateverYouWantToNameIt.ext'; // arbitrary extension $upload = ftp_put($connect, $fileNameOnFTPServer, $newFile, FTP_BINARY); // check upload status if (!$upload) { echo "FTP upload has failed!"; } else { echo "Uploaded {$image} to {$ftpServer} as {$fileNameOnFTPServer}"; } ftp_close($connect); } } </code></pre> <p><strong>Note:</strong> Sometimes <code>file_exists()</code> doesn't behave the way we intended when the path <em>begins</em> with <code>/</code>. For example <code>/path/to/file</code> might exist but <code>file_exists()</code> will think it doesn't unless you remove the beginning "/". One way to get around that is to check it like this:</p> <pre><code>file_exists(substr($newFile, 1)) </code></pre> <p>Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload