Nickdekoning Posted October 17, 2009 Share Posted October 17, 2009 Hello everyone! I'm a complete newb on php, but i am trying to make a script that checks if the users personal dir is already made, if not, the script must make the dir. The nickname of the person is in a cookie. Here is the script: <?php $ftp_server = "ftp.--.com/--/"; $ftp_user_name = "--"; $ftp_user_pass = "--"; // set up basic connection $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"; } //check if dir is available and close connection if(is_dir($_COOKIE['ID_my_site'])) { ftp_close($conn_id); header("Location: member.php"); } else { ftp_mkdir($conn_id, "$_COOKIE['ID_my_site']", 0777); ftp_close($conn_id); header("Location: member.php"); } ?> It gives the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /usr/home/deb17473/domains/nick-dekoning.nl/--/check2.php on line 33 I thinkt the problem is the $cookie tag. Could someone please help me with fixing this script? Link to comment https://forums.phpfreaks.com/topic/178006-script-that-checks-if-personal-dir-is-on-server-if-not-makes-dir/ Share on other sites More sharing options...
Coreye Posted October 17, 2009 Share Posted October 17, 2009 Try: ftp_mkdir($conn_id, $_COOKIE['ID_my_site'], 0777); Link to comment https://forums.phpfreaks.com/topic/178006-script-that-checks-if-personal-dir-is-on-server-if-not-makes-dir/#findComment-938530 Share on other sites More sharing options...
Nickdekoning Posted October 17, 2009 Author Share Posted October 17, 2009 changed it to: ftp_mkdir($conn_id, $_COOKIE['ID_my_site']); , and now the error is: Connected to //website//, for user -- Warning: ftp_mkdir() [function.ftp-mkdir]: Invalid number of arguments in /--/check2.php on line 32 Warning: Cannot modify header information - headers already sent by (output started at /--/check2.php:21) in /--/check2.php on line 34 (I removed one space in the document so the former line 33 is now 32) Link to comment https://forums.phpfreaks.com/topic/178006-script-that-checks-if-personal-dir-is-on-server-if-not-makes-dir/#findComment-938537 Share on other sites More sharing options...
Coreye Posted October 17, 2009 Share Posted October 17, 2009 and now the error is: Connected to //website//, for user -- Warning: ftp_mkdir() [function.ftp-mkdir]: Invalid number of arguments in /--/check2.php on line 32 I'm pretty sure that error means the cookie is empty. I just tested your code and it worked fine. I changed some parts to make it work. <?php $ftp_server = "ftp.mysite.com"; $ftp_user_name = "myusername"; $ftp_user_pass = "mypassword"; /* set up basic connection */ $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!<br />"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name<br />"; } $test = "public_html/testing"; /* check if dir is available and close connection */ if(!@ftp_mkdir($conn_id, $test)) { ftp_close($conn_id); echo "<br />That directory already exists."; } else { @ftp_mkdir($conn_id, $test); ftp_close($conn_id); echo "<br />The directory has been created."; } ?> Link to comment https://forums.phpfreaks.com/topic/178006-script-that-checks-if-personal-dir-is-on-server-if-not-makes-dir/#findComment-938544 Share on other sites More sharing options...
Nickdekoning Posted October 17, 2009 Author Share Posted October 17, 2009 Yes, it works now! You helped me alot! thanks! Here is the final script: <?php $ftp_server = "nick-dekoning.nl"; $ftp_user_name = "--"; $ftp_user_pass = "--"; /* set up basic connection */ $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!<br />"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name<br />"; } /* check if dir is available and close connection */ if(!@ftp_mkdir($conn_id, $_COOKIE['ID_my_site'])) { ftp_close($conn_id); echo "1"; } else { @ftp_mkdir($conn_id, $_COOKIE['ID_my_site']); ftp_close($conn_id); echo "2"; } ?> Link to comment https://forums.phpfreaks.com/topic/178006-script-that-checks-if-personal-dir-is-on-server-if-not-makes-dir/#findComment-938551 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.