saikrishnan1142 Posted July 16, 2013 Share Posted July 16, 2013 (edited) $host = 'XXXXXXXXXXX' $usr = 'XXXXXXXXXXX'; $pwd = 'XXXXXXXXXXX'; $destDir = $_POST['filetype']; $conn_id=ftp_connect($host); $success = ftp_login($conn_id,$usr,$pwd); $rightName = basename($_FILES['uploadfile']['name']); ftp_pasv($conn_id, true); if($success) { ftp_put($conn_id,$destDir.'/'.$rightName,$_FILES['uploadfile']['tmp_name'],FTP_BINARY) or die('Cannot ftp'); ftp_close($conn_id); echo ' Upload Successful'; } The form I am using for upload is this: <form enctype="multipart/form-data" action="upload.php" method="POST"> Type of file: <input name="filetype" id="filetype1" /><br /> Choose a file to upload:<input name="uploadfile" type="file" /><br /> <input type="submit" value="Upload File" /> I have tried multiple options. 'ftp_put' from php's tmp upload location to a working directory and then to a destination directory and 'ftp_put' directly from temporary upload directory of PHP to the desired directory but FTP for some reason does not seem to work at all. It just simply dies. A normal upload using 'move_uploaded_files()' works perfectly. In some of the forums it is mentioned that for ftp to work I can't have 'file' input type and just have a plain text box. I don't understand why that needs to be the case or even if it true. Why is the above code not working? I have checked the permissions on the destination folder and it should not be the issue. Edited July 16, 2013 by saikrishnan1142 Quote Link to comment https://forums.phpfreaks.com/topic/280206-php-ftp-upload-from-html-form/ Share on other sites More sharing options...
requinix Posted July 16, 2013 Share Posted July 16, 2013 You also need to check for an error during the upload ($_FILES['uploadfile']['error']). Your script will "simply die" if ftp_login() fails. How about actually showing some kind of error if that, or ftp_connect(), fails? And do you have your php.ini configured for development? It should have error_reporting = -1 display_errors = onor something more intelligent if you know how to do that. Quote Link to comment https://forums.phpfreaks.com/topic/280206-php-ftp-upload-from-html-form/#findComment-1440945 Share on other sites More sharing options...
saikrishnan1142 Posted July 17, 2013 Author Share Posted July 17, 2013 Unfortunately, my hosting provider provided me the wrong documentation and I was trying to upload the file into a path that was non-existent. FTP root was pointing to a different path to the one that was specified in the documentation and hence the trouble. Quote Link to comment https://forums.phpfreaks.com/topic/280206-php-ftp-upload-from-html-form/#findComment-1441057 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.