Hey all. New to the forum, would much appreciate it if you could help out with my query.
I'm trying to write an FTP uploader page in PHP - I've got a couple of problems.
1) I can only get it to upload files in the same local directory as the php page... and
2) It won't upload images. Works with PDF, Word files, text and html... But mostly I'd want it for images!
Any ideas? 😕
Cheers, Oli.
<?php
$ftp_server="removedforsecurityreasons";
$ftp_user_name="removedforsecurityreasons";
$ftp_user_pass="removedforsecurityreasons";
$file = 'example.jpg';
$remote_file = 'test_h.jpg';
// Open FTP connection
$conn_id = ftp_connect($ftp_server);
// Login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Check the connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected successfully to $ftp_server, under username $ftp_user_name";
}
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
echo "<br>successfully uploaded $file\n, retitled it $remote_file";
} else {
echo "<br>There was a problem while uploading $file\n";
}
// Close the FTP connection
ftp_close($conn_id);
?>