If they point to an external URL for the image in my form I am trying to upload that image to my server. My host doesn't allow fopen() but does allow php ftp() functions like fput() (go figure??)
Here is my code:
Code: Select all
<?php
$pixelURL='http://www.bluesnews.com/images/bluesLogo.gif'; // example external image
$ftp_server = 'ftp.com';
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check 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 to $ftp_server, for user $ftp_user_name";
}
$target_path = "/home/mypath/www/img/subdir/";
$destination_file = $target_path . 'fakefilename.gif';
// upload the file
$upload = ftp_put($conn_id, $destination_file, $pixelURL, FTP_BINARY);
echo '<p>'.print_r($upload).'</p>';
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
Code: Select all
Connected to ftp.com, for user username
1 // output of print_r($upload)
FTP upload has failed!
I assume it is failing because the sourcefile is a URI... is this true?
thanks