I would like some help concerning how to upload a local file from an application to FTP using PHP code. I am an amateur programmer that can read very basic code structure.
Your PHP code on your webserver absolutely cannot access your local files. That would be a security nightmare.
Your application has to actively upload your local file (its contents, not just file name) to the web server using an HTTP file upload (Content-Type: multipart/form-data
).
Then, your PHP code can refer to the uploaded file using $_FILES
variable.
See POST method uploads in PHP.
As you seem to have troubles understanding both client- and server-side code, maybe you should start by first implementing (and debugging) the server-side only. For client-side, use a simple HTTP/HTML file upload form for testing the server-side part. And once you have that up-and-running, replace the HTML upload form with a code in your application.
In other words, if you want to use a PHP built-in support for uploading files, you need to make your application do the same HTTP request as a web browser does, when submitting an HTML <form>
with a file (<input type="file" name="..."/>
).
If you find implementing an HTTP file upload difficult in your (client) development environment (which we do not know anything about), you can use some simpler mechanism, like a simple HTTP POST
request with a file contents (no multipart, just binary data of the file). Though I believe that most desktop app most frameworks support HTTP file upload these days natively.