Uploading images with FTP_PUT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ojeffery
Forum Newbie
Posts: 4
Joined: Mon Apr 24, 2006 9:56 am

Uploading images with FTP_PUT

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post. your. code.
ojeffery
Forum Newbie
Posts: 4
Joined: Mon Apr 24, 2006 9:56 am

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
Post Reply