How to Use
As we all know, using FTP to upload, copy, and delete a large number of files is quite slow. It takes more than half an hour to upload a wordpress, and it takes half an hour to delete it... The above process can be completed in less than 3 seconds after the web page is uploaded with simple php code (especially for websites such as mobile phones ...)
Note: Copy and save the code in this article as a xxx. php file and upload it to the space to open it (modify the corresponding modification)
PHP File Management 1. Upload and decompress the code
- < ?php
- exec("fetch http://cn.wordpress
.org/wordpress-2.8-zh_CN.zip");
- exec("tar xvfz wordpress-2.8-
zh_CN.zip");
- ?>
This is the wordpress upload and decompress code. You can also use the following code to decompress the file (you can also obtain network files)
- < ?php
- exec("tar xvfz wordpress
-2.8-zh_CN.zip");
- ?>
PHP File Management 2. Copy the code
Generally, the above extraction will be decompressed to a new folder, and if you want to copy it to the root directory, you can use the following code (also available for mobile files, but this will not be introduced for backup) (here, the X-Dragon space is used as an example. You need to change the path yourself)
- < ?
- exec("cp -Rf /usr/virtual/leo2351960
/flysh.co.tv/public_html/wordpress/
/usr/virtual/leo2351960/flysh.co.
tv/public_html/");
- ?>
The above code copies the wp folder to the root directory. There are two paths in front of the file to be moved (folder), followed by the target path, and the path must be an absolute path.
PHP File Management 3. delete a file (folder)
- < ?
- exec("rm -r /usr/virtual/
leo2351960/flysh.co.tv/
public_html/wordpress");
- ?>
Note: delete the folder with caution. This action is too fast and you have no time to regret it (You have to reload the folder accidentally deleted last time)
PHP File Management 4. Modify file (folder) Permissions
- < ?php
- exec("chmod -R 777 /v /usr/virtual
/leo2351960/flysh.co.tv/public_html/xxx.php");
- exec("chmod -R 777 /v /usr/virtual
/leo2351960/flysh.co.tv/public_html/up");
- ?>
Modify the permissions of a large number of file folders!
PHP file management 5. Batch delete database tables with the same prefix
This was found by the 007 brother of free8 (he found pm and I, really good guy ~), Paste it by the way
- <? Php
- Function deldata ($ dbname, $ tableflag ){
- $ Db_host = 'localhost ';
- $ Db_port = '000000 ';
- $ Db_user = 'username ';
- $ Db_pass = 'Password ';
- $ Connect = mysql_connect ($ db_host,
$ Db_user, $ db_pass );
- Mysql_select_db ($ dbname );
- $ Result = mysql_query ("show table
Status from $ dbname ", $ connect );
- $ Data = mysql_fetch_array ($ result );
- While ($ data = mysql_fetch_array ($ result )){
- $ Table = mysubstr ($ data [Name], "_");
- If ($ table = $ tableflag ){
- // Use for testing
- /* Echo $ data [Name];
- Echo "<br> ";
- Echo $ table;
- Echo "<br> ";*/
- Mysql_query ("drop table $ data [Name]");
- }
- }
- Return true;
- }
- /* Truncates all the character functions before a specific character
- * $ Str is the string to be truncated.
- * $ Flag specific characters such as "_"
- */
- Function mysubstr ($ str, $ flag ){
- $ Pos = strpos ($ str, $ flag );
- Return substr ($ str, 0, $ pos );
- }
- ?>
- <? Php // test
- $ Dbname = "database ";
- // Database Name
- $ Tableflag = "wp ";
- // The prefix of the table to be deleted. Only tables with this prefix can be deleted.
Indicates the user
- Deldata ($ dbname, $ tableflag );
- // $ Test = mysubstr ("cdb_account_log ","_");
- // Echo $ test;
- ?>
Note that the above username and password have the following database and table prefix.
Okay. The above is some practical code for PHP file management. There are many other things that you may find yourself ~