dhorn spm Posted June 30, 2008 Share Posted June 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
br0ken Posted June 30, 2008 Share Posted June 30, 2008 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 Quote Link to comment Share on other sites More sharing options...
kivison Posted June 30, 2008 Share Posted June 30, 2008 If the user has a unique directory for the upload I would include it on the database record. if the directory is just the user name then you can use the user name as the path i.e /web/user_area/$username/$uploaded_file Keith Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 30, 2008 Share Posted June 30, 2008 http://us2.php.net/ftp Quote Link to comment Share on other sites More sharing options...
dhorn spm Posted June 30, 2008 Author Share Posted June 30, 2008 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! Quote Link to comment Share on other sites More sharing options...
br0ken Posted June 30, 2008 Share Posted June 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 30, 2008 Share Posted June 30, 2008 // 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'; } } } Quote Link to comment Share on other sites More sharing options...
dhorn spm Posted June 30, 2008 Author Share Posted June 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
dhorn spm Posted June 30, 2008 Author Share Posted June 30, 2008 // 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. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 30, 2008 Share Posted June 30, 2008 I didn't find it, I wrote it. Quote Link to comment Share on other sites More sharing options...
dhorn spm Posted June 30, 2008 Author Share Posted June 30, 2008 I didn't find it, I wrote it. Wow thanks man!! That's awesome. I'm about to go to lunch but I'll try it out when I get back and give you some feedback. Major props!! Quote Link to comment Share on other sites More sharing options...
dhorn spm Posted June 30, 2008 Author Share Posted June 30, 2008 Hey little guy I'm having some problems with my server right now so I'll have to get back with you about the code, but it looks like it will exactly what I want it to. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted June 30, 2008 Share Posted June 30, 2008 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.