Jump to content

Upload to FTP via PHP?


dhorn spm

Recommended Posts

Hello,

 

I need to make a page on my website that allows users to login with a username and password, then allows them to browse their computer for a file and upon clicking submit it should send their file to a folder on an FTP site, and the folder submitted to is decided by the username they used to login (different people have different file drop locations). It doesn't need a registering function, we will manual add names/passwords to the database.

 

Any ideas, suggestions, etc.?

 

Is this possible with PHP?

 

I've been working really hard on this and so far have no results.

 

Thanks,

Daniel

Link to comment
https://forums.phpfreaks.com/topic/112604-upload-to-ftp-via-php/
Share on other sites

It is possible with PHP, yes. If you want to just upload the file to a folder on your server you'll need to look into PHP Uploads. There are plenty of tutorials on this on the web just do a simple Google search and you should plenty information to get you going.

 

If it's FTP you're after consult this link...

 

http://www.w3schools.com/PHP/php_ref_ftp.asp

 

 

It is possible with PHP, yes. If you want to just upload the file to a folder on your server you'll need to look into PHP Uploads. There are plenty of tutorials on this on the web just do a simple Google search and you should plenty information to get you going.

 

If it's FTP you're after consult this link...

 

http://www.w3schools.com/PHP/php_ref_ftp.asp

 

 

 

I've done several google searches and I've come close a few times but haven't really found what I'm looking for.  I'm brand spanking new to PHP and it seems to me that you would need a lot of PHP coding knowledge and experience, which I do not have. I'll keep trying, and I appreciate your help.

 

Please continue to give input on this issue you guys!

 

Thanks!

// set up basic connection
$ftp_server = 'my.server.com';
$ftp_user_name = 'ftp_user_name';
$ftp_user_pass = 'ftp_user_password';
$conn_id = ftp_connect($ftp_server); 

// login with username and password
$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 ";
    }

foreach ($_FILES["file"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
	$tmp_name = $_FILES["file"]["tmp_name"][$key];
	if($upload = ftp_put($conn_id, "/upload/dir/image.jpg", $tmp_name, FTP_BINARY)){
		echo 'File uploaded';
	}else{
		echo 'Upload File Error';
	}
}
}

It may seem like a hard thing to do but that's only because you're thinking of the project as a whole. Try breaking it up and doing little parts and combining them and it will seem much easier.

 

I know. I didn't just start working on this. This is the third week, and it's becoming very frustrating. I haven't even really gotten to the FTP part yet I'm trying to get my login/passwords to work. I know how to go about doing it, but Dreamweaver won't let me connect to MySQL.

 

It keeps giving me an error message saying "HTML Error Message 405 - Method Not Allowed." I googled it with no help. I then called Adobe support who also couldn't help and said they'd have a Senior Technician call me. Well he called me, couldn't resolve the issue, told me to try installing PHP on a new machine and said that he'd send me instructions on how to do that. He also said he'd call back the next day to make sure I had everything working. Well I never got the instructions even though I have him two email addresses, and I never received a call back.

 

I eventually looked up a guide on installing PHP into a web server because the first time I installed it I just did it. The guide was helpful, but I'm still getting error messages when trying to connect Dreamweaver on my MySQL server. Worst part is this is just the local part on my machine; after I get this figured out I'll have to go to our internet host and set it all up there.

// set up basic connection
$ftp_server = 'my.server.com';
$ftp_user_name = 'ftp_user_name';
$ftp_user_pass = 'ftp_user_password';
$conn_id = ftp_connect($ftp_server); 

// login with username and password
$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 ";
    }

foreach ($_FILES["file"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
	$tmp_name = $_FILES["file"]["tmp_name"][$key];
	if($upload = ftp_put($conn_id, "/upload/dir/image.jpg", $tmp_name, FTP_BINARY)){
		echo 'File uploaded';
	}else{
		echo 'Upload File Error';
	}
}
}

 

Where did you find this? It looks familiar. I think I saw this or something similar on About.com PHP tutorials but I never got it to work.

it uses an array of files to upload I forgot to mention in the previous post.

 

so...

 

<form action="upload.php" method="post" enctype="multipart/form-data">
File 1: <input type="file" name="files[]" /><br />
File 2: <input type="file" name="files[]" /><br />
<input type="submit" value="Upload" />
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.