greengo Posted May 12, 2007 Share Posted May 12, 2007 hi does anyone tell me why this script does'n work? I use a post method in the html form. <?php $file = $_FILES['file']; $ftpServer = "greengo.orgfree.com"; $ftpUser = "username"; $ftpPass = "+++++"; $post_dir= "upload/files/"; if($file) echo "got data"; $conn = @ftp_connect($ftpServer) or die("Cannot initiate connection to host"); $login = @ftp_login($conn, $ftpUser, $ftpPass or die("Cannot login" ); $upload = @ftp_put($conn, $post_dir, $file, FTP_BINARY); else echo "haven't got data!!!"; if($upload) echo "<table width='500' border='0'><tr><td><div align='center'><h2>File uploaded OK.</h2></div></td></tr><tr><td><div align='center'><a href='http://greengo.orgfree.com/upload'><h3>GO BACK<h3></a></div></td></tr></table>"; else echo "<table width='500' border='0'><tr><td><div align='center'><h2>File upload failed.</h2></div></td></tr><tr><td><div align='center'><a href='http://greengo.orgfree.com/upload'><h3>GO BACK<h3></a></div></td></tr></table>"; ftp_quit($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/ Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 Any errors? Try using the {}s with your if and else statements. Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251319 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 remove the @'s and post the errors ? what makes you say it doesn't work ? Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251320 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 REMOVE YOUR PASSWORD AND USER NAME (CLICK EDIT ON YOUR LAST POST) Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251321 Share on other sites More sharing options...
greengo Posted May 12, 2007 Author Share Posted May 12, 2007 It doesn't give me any error just a white page no echo no die. Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251327 Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 Try with {}s? Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251329 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 you don't need {}'s for one lines add print_r($_FILES); at the start to check data comming inn also add echo "Sending"; just before $upload = @ftp_put($conn, $post_dir, $file, FTP_BINARY); what results do you get ? Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251331 Share on other sites More sharing options...
greengo Posted May 12, 2007 Author Share Posted May 12, 2007 hey mad still a white page Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251334 Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 Well something's wrong because every section of that code should be echoing. Try removing the @s? Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251336 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 OK last test.. add die("NOTHING TO DO"); at the very top of the script.. now try if you don't get that then look at the form again (maybe post it) Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251338 Share on other sites More sharing options...
greengo Posted May 12, 2007 Author Share Posted May 12, 2007 without @ I still get a white page seems like I don't recive from the form!?! Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251340 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 try my suggestion that will prove if the page is being called or not Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251341 Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 In that case, at the top of the file the form goes to: <?php print_r($_POST); ?> To see if it receives any values or not. Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251342 Share on other sites More sharing options...
greengo Posted May 12, 2007 Author Share Posted May 12, 2007 no mad the die doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251347 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 OK, check your form.. as that seams to be the problem, (as i said maybe posting it will help) ie form.php <form ....> upload.php <?php print_r($_POST); ?> so we know what the file names are Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251351 Share on other sites More sharing options...
yzerman Posted May 12, 2007 Share Posted May 12, 2007 do you have permissions to run PHP on the server you are using? Is PHP even on your server? Did you upload the file before trying to reload the page (I do that alot and cant figure out why the change doesn't work) Did you upload the file to the right directory? (see last statement) Check the first 2, if those are ok, check the next 2. If all 4 of these are good, then write this in notepad: <? phpinfo(); ?> save the file as phpinfo.php, then browse to the page - if you get something, PHP works, if not - your server is broke (or your not allowed to use PHP) Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251353 Share on other sites More sharing options...
greengo Posted May 12, 2007 Author Share Posted May 12, 2007 the form works I already tested it with another script on the server n I alredy did all those things yze <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>File sender</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/javascript"> <!-- function checkform ( form ) { if (form.file.value == "") { alert( "Please enter a file." ); form.file.focus(); return false ; } return true ; } </script> </head> <body> <form name="form1" enctype="multipart/form-data" method="post" action="ftp_php.php" onSubmit="return checkform(this);"> <table width="500" border="0" align="center"> <tr> <td><div align="center"> <input name="file" type="file"> <br> </div></td> </tr> <tr> <td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif">You can send one file at the time.<br> If you want to send more the one file at the time you can make a zip file and send it. </font></div></td> </tr> <tr> <td> <div align="center"> <input type="submit" name="Submit" value="Send"> </div></td> </tr> </table> <div align="center"></div> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251355 Share on other sites More sharing options...
greengo Posted May 12, 2007 Author Share Posted May 12, 2007 no mad it doesn't print anything the page that I'm working on is http://greengo.orgfree.com/upload/ Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251362 Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 Try this <?php $file = $_FILES['file']; $ftpServer = "ggfdfgdf"; $ftpUser = "dfgdfgfdg"; $ftpPass = "dfgdfgdfgdf"; $post_dir= "upload/files/"; if($file) { echo "got data"; $conn = @ftp_connect($ftpServer) or die("Cannot initiate connection to host"); $login = @ftp_login($conn, $ftpUser, $ftpPass) or die("Cannot login" ); $upload = ftp_put($conn, $post_dir, $file, FTP_BINARY); }else{ echo "haven't got data!!!"; } if($upload) { echo "<table width='500' border='0'><tr><td><div align='center'><h2>File uploaded OK.</h2></div></td></tr><tr><td><div align='center'><a href='http://greengo.orgfree.com/upload'><h3>GO BACK<h3>[/a]</div></td></tr></table>"; }else{ echo "<table width='500' border='0'><tr><td><div align='center'><h2>File upload failed.</h2></div></td></tr><tr><td><div align='center'><a href='http://greengo.orgfree.com/upload'><h3>GO BACK<h3>[/a]</div></td></tr></table>"; } ftp_quit($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51066-php-ftp-upload/#findComment-251369 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.