Can a script be executed locally on XAMPP and specify a directory path over FTP in PHP?
To execute a script locally on XAMPP and specify a directory path over FTP in PHP, you can use the FTP functions in PHP to connect to the FTP server and upload the file to the specified directory. You can use the `ftp_put()` function to upload the file to the FTP server.
<?php
$ftp_server = "ftp.example.com";
$ftp_user = "username";
$ftp_pass = "password";
$local_file = "localfile.txt";
$remote_file = "/path/to/remote/file.txt";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $local_file, FTP_ASCII)) {
echo "File uploaded successfully";
} else {
echo "Failed to upload file";
}
// close the connection
ftp_close($conn_id);
?>
Keywords
Related Questions
- What are some key considerations for establishing and maintaining a connection to a MySQL database in PHP?
- What are the best practices for choosing between PDO and MySQLi for object-oriented programming in PHP?
- Is it recommended to separate HTML code with embedded PHP code into a separate file and include it using the include function in PHP?