|
| | #1 (permalink) |
| Whiskey Tango Foxtrot Join Date: Aug 2006
Posts: 2,027
| PHP script question Anyone familiar with PHP that could help me with a script? I need a script that can delete a file via FTP, that can be ran with a CronJob. Any help would be appreciated ![]()
__________________ |
| | |
| | #2 (permalink) |
| Registered User Join Date: May 2003
Posts: 264
+6 Internets | This should be pretty easy to do. Get started here: PHP: FTP - Manual .. basically you will use ftp_connect, ftp_login, ftp_chdir if necessary, then ftp_delete, in that order. |
| | |
| | #3 (permalink) |
| Registered User Join Date: May 2003
Posts: 264
+6 Internets | Some further help.. simplified but this should get you started. $conn = ftp_connect('your ftp server') or die('Failed to connect.'); $login = ftp_login($conn, 'username','password') or die('Failed to login.'); //if needed: //$chgdir = ftp_chdir($conn, 'directory_name') or die('Failed to change directory'); //can also just type in the path to the file in ftp_delete instead of changing directory $delete = ftp_delete($conn, 'path_to_file') or die('Failed to delete.'); |
| | |
| | #4 (permalink) |
| Romo is a manwhore | Hmm, this looks like a good thread for my question. I'm currently attempting a project which requires a lot of database calls across what is likely to be a lot of different .php files. Rather than have each script individually call the database (mysqli_connect()), would it be prudent for me to create a class which does this and simply call the class when necessary? |
| | |
| | #5 (permalink) |
| Registered User Join Date: May 2003
Posts: 264
+6 Internets | Yes, the way I do it is have a class called something like opendb.php that contains the mysql_connect call with the user/pass and anything else you want (ie, log functions, any specific routine that must be ran before or after connecting to the db, etc.) then in the php files that will use this, you can use require or require_once to run the opendb.php or whatever you name it. Generally, if on a webserver, the opendb.php would be in a folder that is hidden from everyone but owner (permissions would be 700 for unix webserver). |
| | |
| | #6 (permalink) |
| Romo is a manwhore | Thanks. It's a couple of additional lines in the code but now I don't have to type out that damned mysqli_connect function for god knows how many files this thing will end up using. Plus, when I change the user from Root to something a bit more secure, I don't need to tear my hair out on the updating. |
| | |
| | #8 (permalink) |
| Limey Bastard Join Date: Mar 2004 Location: London innit
Posts: 742
| Code:
Edit: At work now, here's my db class. Username etc are hard coded, easy enough to change that. Code:
Last edited by Slide : 07-09-2008 at 02:13 AM. |
| | |
| | #9 (permalink) |
| Romo is a manwhore | Heh, I'm just starting out with learning PHP though it's not really a complex language so that's not too hard to follow. My problem is that I learned procedural and am just now beginning to grasp the basics of OOP. I threw this together the other day: Code:
Code:
|
| | |
| | #10 (permalink) | |
| Registered User Join Date: May 2003
Posts: 264
+6 Internets | You don't even have to bother with a class or function. If you just put: Quote:
Now if you're going to be opening multiple concurrent connections to the same db for whatever reason, then your method is fine. | |
| | |
| | #11 (permalink) | |
| Limey Bastard Join Date: Mar 2004 Location: London innit
Posts: 742
| Quote:
| |
| | |
| | #13 (permalink) | |
| Limey Bastard Join Date: Mar 2004 Location: London innit
Posts: 742
| Quote:
| |
| | |
| | #15 (permalink) | |
| Limey Bastard Join Date: Mar 2004 Location: London innit
Posts: 742
| Quote:
![]() | |
| | |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
| |