Page 1 of 1

Uploading images with FTP_PUT

Posted: Mon Apr 24, 2006 10:00 am
by ojeffery
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! :cry:

Any ideas?

Cheers, Oli.

Posted: Mon Apr 24, 2006 11:27 am
by feyd
post. your. code.

Posted: Tue Apr 25, 2006 3:34 am
by ojeffery
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Fair point...   

I'm uploading to an ISA server, will this make a difference?

Code: Select all

<?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); 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Apr 25, 2006 3:57 am
by feyd
supplying a full path to whatever file you wish to upload will allow you to upload any file from anywhere in the system (privileges withstanding.) As for not being able to upload images, I don't see anything that would make such a behaviour happen. Maybe it's something on that server's end of things?