Results 1 to 2 of 2

Thread: PHP File Upload using FTP_PUT()

  1. #1
    Join Date
    Feb 2004
    11th Dimension

    PHP File Upload using FTP_PUT()

    Hey all,

    I'm trying to make a simple script for uploading a file to my web server. Here's the code:

    <form action="client_upload_confirmation.php" method="post" enctype="multipart/form-data">
    		<input name="source_file" type="file" />
    		<input type="submit" value="Upload" title="Upload your file" />
    		// gets the file from the input form and puts it into a PHP array
    		$source = $_FILES["source_file"];
    		// extracts the source file name
    		$source_file = $_FILES["source_file"]["name"];
    		// sets the target directory on the web server
    		$target_directory = "_uploads/";
    		// sets the target file name
    		$destination_file = $target_directory . $source_file;
    		// includes the FTP variables stored in another PHP file
    		// connects to the FTP server
    		$connection = ftp_connect($ftp_server);
    		// displays an error message if the connection cannot be made
    		if (!$connection) {
    			echo '<p>Could not connect to the FTP server.</p>';
    		} else {
    			echo '<p>Connection established.</p>';
    		// logs in to the FTP server
    		$login = ftp_login($connection, $ftp_username, $ftp_password);
    		// displays an error message if the script cannot log in
    		if (!$login) {
    			echo '<p>Could not log in to the FTP server.</p>';
    		} else {
    			echo '<p>Login successful.</p>';
    		// uploads the file
    		$upload = ftp_put($connection, $destination_file, $source_file, FTP_BINARY);
    		// displays an error message if the file could not be uploaded
    		if (!$upload) {
    			echo "FTP upload has failed!";
    		} else {
    			echo "Uploaded $source_file";
    		// close the FTP stream
    The problem I have is that it doesn't work! What am I doing wrong?

    I get the confirmation messages that the connection has been established and that the login was successful, but the actual upload fails.

    I've checked my php.ini file and it has uploads enabled, so I'm really stuck.

    Any help would be awesome, thanks!

    Natalie Portman Addict

  2. #2
    Join Date
    Feb 2004
    11th Dimension
    I've tried checking the permissions for the folder, and they're set to 755, and I can also use a PHP script to successfully read from the directory, but for some reason the upload just doesn't work.

    Can anyone think of any other reasons (possibly to do with the PHP.ini settings) why my script won't work?

    Thanks everyone.

    Natalie Portman Addict

Similar Threads

  1. PHP Include: If file not found, can i direct to a default file?
    By ukcoolat in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 04 Nov 2005, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts