How can the PHP language be used for file management in space, to provide us with a good spatial layout? Today we will introduce a simple way to implement the PHP file management.
- PHP pre-defined variable array type overview
- PHP uploaded_files Function Usage Tips
- Experience sharing PHP display images
- An in-depth discussion on how to implement PHP generated thumbnails
- Using loops to implement a list of PHP classifications
As we all know, with FTP upload, copy, delete a large number of files is quite slow, upload a WordPress will be more than half an hour, delete it also to half an hour ... And with a simple PHP code upload and then open the Web page, 3 seconds to get the above process can be done, it is very cool (especially for me this kind of mobile phone play website ...) )
Note: Copy the code in the text to the xxx.php file upload to the space to open it (the corresponding modification needs to be modified)
PHP file management 1. Uploading and decompression 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 decompression code, you can also use the following code to extract files (also can get network files)
- < PHP
- EXEC ("Tar xvfz WordPress
-2.8-zh_cn.zip ");
- ?>
PHP file management 2. Copying code
Usually the above decompression will be extracted to a new folder, and if you want to copy to the root directory, you can use the following code (there are also mobile files, but for the backup is not introduced) (here to the Dragon space for example, the path needs to change itself)
- <?
- EXEC ("cp-rf/usr/virtual/leo2351960
/flysh.co.tv/public_html/wordpress/
/usr/virtual/leo2351960/flysh.co.
Tv/public_html/");
- ?>
Above this is the WP folder to the root directory to copy the code, there are two paths, the front is the need to move the file (folder), followed by the target path, the path must be absolute path
PHP file management 3. deleting files (clips)
- <?
- EXEC ("Rm-r/usr/virtual/
leo2351960/flysh.co.tv/
Public_html/wordpress ");
- ?>
Note, careful deletion, this action too fast, regret too late (the last time accidentally deleted a folder to be re-loaded again)
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 ");
- ?>
Corresponding modification can complete a large number of file folder permissions modification, convenient!
PHP file Management 5. Bulk delete the same prefix database table
This is Free8 's 007 brothers found (he found also pm me, really good ah ~), by the way affixed
- < PHP
- function Deldata ($dbname, $tableflag) {
- $db_host = ' localhost ';
- $db_port = ' 3306 ';
- $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) {
- For testing purposes
- /*echo $data [Name];
- echo "< br>";
- Echo $table;
- echo "< br>"; * *
- mysql_query ("drop table $data [Name]");
- }
- }
- return true;
- }
- /* All character functions before a specific character is intercepted
- * $str for the string to be intercepted
- * $flag specific words such as "_"
- */
- function Mysubstr ($STR, $flag) {
- $pos=strpos ($str, $flag);
- Return substr ($str, 0, $pos);
- }
- ?>
- < PHP//test
- $dbname="database";
- Database name
- $tableflag="WP";
- The table to be removed is prefixed with the tables with this prefix removed
, which user is marked out
- Deldata ($dbname, $tableflag);
- $test=mysubstr ("Cdb_account_log", "_");
- Echo $test;
- ?>
Notice that the username and password above are modified and the database and table prefixes below
OK, the above is the PHP file management Some practical code, there are a lot of people find their own, I like the fast and convenient gadgets ~
Simple implementation of PHP file management