Liquid Fire Posted November 7, 2006 Share Posted November 7, 2006 how would I go about using the ftp commands in php to upload file through a script? Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/ Share on other sites More sharing options...
btherl Posted November 7, 2006 Share Posted November 7, 2006 There are some example here: http://sg.php.net/manual/en/ref.ftp.php Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-120722 Share on other sites More sharing options...
Liquid Fire Posted November 7, 2006 Author Share Posted November 7, 2006 well i do that and when i run the script from the live server i get this error:Warning: ftp_put(c:/test.gif) [function.ftp-put]: failed to open stream: No such file or directory in /home/.ornate/kdiadmin/kaizendigital.com/wowguild/includes/ftp.php on line 134Now When I run the file on my local machine the file get uploaded to the live server like it should and the file does exist on my machine at c:\test.gif. The only thin gi can think of is that the script is looking for c:\test.gif on the machine the server is running from and if not then what do i have to do different to get it to work on the live server becuase if work great when i run it on my machine on my localhost. Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-120740 Share on other sites More sharing options...
doni49 Posted November 7, 2006 Share Posted November 7, 2006 what's your code look like? Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-120745 Share on other sites More sharing options...
Liquid Fire Posted November 7, 2006 Author Share Posted November 7, 2006 [code]$upload_file_path = $_POST["filedirectory"] . $_POST["filename"];if($ftp->UploadFile($upload_file_path, $_POST["filename"], FTP_TEXT)){ print("Image Uploaded.");}else{ print("Could not upload image.");}[/code][code]public function UploadFile($local_file_path, $server_file_path, $file_type){ if(ftp_put($this->GetFTPConnection(), $server_file_path, $local_file_path, $file_type)) { return true; } else { return false; }}[/code]that is all the code you need to know that deals with my problem. Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-120756 Share on other sites More sharing options...
Liquid Fire Posted November 7, 2006 Author Share Posted November 7, 2006 anyone see anything wrong with that code. Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-120944 Share on other sites More sharing options...
Kelset Posted November 7, 2006 Share Posted November 7, 2006 Just a quick stab in the dark here and I'm new but should this line contain the filename?[code]$upload_file_path = $_POST["filedirectory"] . $_POST["filename"];[/code]The path for the file to be uploaded should not have the file name in it right? not sureCheers!Stephen Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-120952 Share on other sites More sharing options...
Liquid Fire Posted November 7, 2006 Author Share Posted November 7, 2006 If you read my code you would notice the the $upload_file_path is the path to the file that is being uploaded. And according to this http://sg.php.net/manual/en/function.ftp-put.php, you do need the file name for the file on the server. Anyone else see anything wrong?Does ftp_put look for the file on the machine the script is running on( as in the server machine ) or the machine that is accessing the script( as in the user-end machine, which is where the file is located )? Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121049 Share on other sites More sharing options...
doni49 Posted November 7, 2006 Share Posted November 7, 2006 Try the following as a troubleshooting tool (it's only temporary):[code]$upload_file_path = $_POST["filedirectory"] . $_POST["filename"];echo "<br />Upload File Path: " . $upload_file_path; // <--Add this line and re-run the script. See if anything looks odd.if($ftp->UploadFile($upload_file_path, $_POST["filename"], FTP_TEXT))[/code] Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121076 Share on other sites More sharing options...
Liquid Fire Posted November 7, 2006 Author Share Posted November 7, 2006 the output from that is:Upload File Path: c:/test.giforUpload File Path: c:\test.gif Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121092 Share on other sites More sharing options...
Liquid Fire Posted November 8, 2006 Author Share Posted November 8, 2006 does that help you any? Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121359 Share on other sites More sharing options...
doni49 Posted November 8, 2006 Share Posted November 8, 2006 No it doesn't. That line of code will only post one or the other--not both.I haven't used PHP on windows so I can only assume it follows the windows standard, but windows will NOT understand what c:/test.gif is. If you're really passing that as your file name/path, then that might very well be your problem.Then when it can't find the file, you get FALSE as your test value. Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121370 Share on other sites More sharing options...
doni49 Posted November 8, 2006 Share Posted November 8, 2006 P.S. if you're having trouble dealing with having a back slash in the form field, try [b]add_slashes($_POST["filedirectory"]);[/b] Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121372 Share on other sites More sharing options...
Liquid Fire Posted November 8, 2006 Author Share Posted November 8, 2006 The server is unix, the livwe one and my localhost test server is windows. when i run the script on my test server,, c:/ or c:\ works and the file gets uploaded but when i run it from my live server, neither works. the thing that confuses me is that is works on my test server and not on my live server. the error message i get on the live server is:Warning: ftp_put(c:\test.gif) [function.ftp-put]: failed to open stream: No such file or directory in /home/.ornate/kdiadmin/kaizendigital.com/wowguild/includes/ftp.php on line 134Could not upload image.What that tells me is that is can't find the file which make me to believe that it is not looking on my computer for the file, which is where it is, but it is looking for c:\test.gif on the server machine at the hosting company. what does that error tell you? Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121580 Share on other sites More sharing options...
Liquid Fire Posted November 8, 2006 Author Share Posted November 8, 2006 anyone else with any light to shine on my problem? Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121806 Share on other sites More sharing options...
Liquid Fire Posted November 9, 2006 Author Share Posted November 9, 2006 well since it is impossible, or atleast no one here knows hwo to, how can i upload file with using php ftp commands. Link to comment https://forums.phpfreaks.com/topic/26396-how-would-i-upload-file-using-ftp-and-php/#findComment-121941 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.