MarcinUK Posted September 4, 2014 Share Posted September 4, 2014 (edited) Good afternoon, I wrote a script for uploading files to ftp server. When I lunch this on local server(wamp) it does upload files into ftp server. When I run the same script on my host provider(iPage) it doesn't upload files. Any advices? Have a look at the code please. form <code> <form enctype="multipart/form-data" action="upload.php" method="post"> <table > <tr> <td> <input name="userfile" type="file"> </td> </tr> <tr> <td > <input type="Submit" value="Add file"> </td> </tr> </table></form> </code> upload.php <code> <?php######################################################################/*For remote servers*/ini_set("max_execution_time", 100000000000); // execution time must be bigger for larger files$file = basename($_FILES['userfile']['name']);//$remote_file = "/home/users/web/b1729/ipg.marcinkopecnet/remote_upload/$file";$remote_file = "/remote_upload/$file";/*Define ftp server connection*/$ftp_server = "right_server";$ftp_user_name = "right_username";$ftp_user_pass = "right_password";// set up basic connection$conn_id = ftp_connect($ftp_server, 21) or die ("Cannot connect to host");// turn passive mode onftp_pasv($conn_id, true);// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("Cannot login");// upload a fileif ($upload = ftp_put($conn_id, $remote_file, $_FILES['userfile']['tmp_name'], FTP_BINARY)) { // check upload status: print (!$upload) ? 'Cannot upload' : 'Upload complete'; print "\n"; //echo "successfully uploaded $file\n"; }else { echo "There was a problem while uploading $file\n"; }// close the connectionftp_close($conn_id);######################################################################?> </code> Edited September 4, 2014 by MarcinUK Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 5, 2014 Share Posted September 5, 2014 "The script doesn't upload files" is a bit vague, don't you think? Have you turned on error reporting? What error messages do you get then? Also, do you realize that this script has no protection whatsoever? It uploads any file to any location, which means you might as well print your FTP credentials on the screen. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 5, 2014 Share Posted September 5, 2014 Interesting. You want to upload files into an ftp server but using an html form instead an ftp client ??? That sounds me like you want to watch a movie using a code editor Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted September 5, 2014 Solution Share Posted September 5, 2014 If you are uploading the files to your site via HTML form then there is no need for the ftp functions. The file has already been uploaded when the form is submitted, you'd use move_uploaded_file to place the file where you want it to be saved. Quote Link to comment Share on other sites More sharing options...
MarcinUK Posted September 5, 2014 Author Share Posted September 5, 2014 (edited) "The script doesn't upload files" is a bit vague, don't you think? Have you turned on error reporting? What error messages do you get then? Also, do you realize that this script has no protection whatsoever? It uploads any file to any location, which means you might as well print your FTP credentials on the screen. I turned on error reporting and server doesn't report anything. According to if,else statesment script returns "There was a problem while uploading $file\n". That's true the script hasn't any protection but I want to let admin to upload any files to the selected location($remote_file = "/remote_upload/$file";). My colegue wants use form insted ftp client. That's only one reason of writing this script. Interesting. You want to upload files into an ftp server but using an html form instead an ftp client ??? That sounds me like you want to watch a movie using a code editor I use ftp client but my colegue wants uplad files using form. He is just a user of the site. If you are uploading the files to your site via HTML form then there is no need for the ftp functions. The file has already been uploaded when the form is submitted, you'd use move_uploaded_file to place the file where you want it to be saved. This is a great solution. Thank. Now it works as I wanted. Cheers. Edited September 5, 2014 by MarcinUK Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 5, 2014 Share Posted September 5, 2014 WTF? You tried to use FTP to move a local file to a local destination? I think you're very, very confused, MarcinUK. 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.