Simple implementation of PHP file management

Source: Internet
Author: User
Tags php language php file upload

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

    1. < PHP
    2. EXEC ("Fetch http://cn.wordpress
      . Org/wordpress-2.8-zh_cn.zip ");
    3. EXEC ("Tar xvfz wordpress-2.8-
      Zh_cn.zip ");
    4. ?>


This is the WordPress upload decompression code, you can also use the following code to extract files (also can get network files)

    1. < PHP
    2. EXEC ("Tar xvfz WordPress
      -2.8-zh_cn.zip ");
    3. ?>


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)

    1. <?
    2. EXEC ("cp-rf/usr/virtual/leo2351960
      /flysh.co.tv/public_html/wordpress/
      /usr/virtual/leo2351960/flysh.co.
      Tv/public_html/");
    3. ?>


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)

    1. <?
    2. EXEC ("Rm-r/usr/virtual/
      leo2351960/flysh.co.tv/
      Public_html/wordpress ");
    3. ?>

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

    1. < PHP
    2. EXEC ("Chmod-r 777/v/usr/virtual
      /leo2351960/flysh.co.tv/public_html/xxx.php ");
    3. EXEC ("Chmod-r 777/v/usr/virtual
      /leo2351960/flysh.co.tv/public_html/up ");
    4. ?>

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

  1. < PHP
  2. function Deldata ($dbname, $tableflag) {
  3. $db_host = ' localhost ';
  4. $db_port = ' 3306 ';
  5. $db_user = ' username ';
  6. $db_pass = ' password ';
  7. $Connect =mysql_connect ($db _host,
    $db _user, $db _pass);
  8. mysql_select_db ($dbname);
  9. $result = mysql_query ("Show Table
    Status from $dbname ", $connect);
  10. $data=mysql_fetch_array ($result);
  11. while ($data=mysql_fetch_array ($result)) {
  12. $table=mysubstr ($data [Name], "_");
  13. if ($table== $tableflag) {
  14. For testing purposes
  15. /*echo $data [Name];
  16. echo "< br>";
  17. Echo $table;
  18. echo "< br>"; * *
  19. mysql_query ("drop table $data [Name]");
  20. }
  21. }
  22. return true;
  23. }
  24. /* All character functions before a specific character is intercepted
  25. * $str for the string to be intercepted
  26. * $flag specific words such as "_"
  27. */
  28. function Mysubstr ($STR, $flag) {
  29. $pos=strpos ($str, $flag);
  30. Return substr ($str, 0, $pos);
  31. }
  32. ?>

    1. < PHP//test
    2. $dbname="database";
    3. Database name
    4. $tableflag="WP";
    5. The table to be removed is prefixed with the tables with this prefix removed
      , which user is marked out
    6. Deldata ($dbname, $tableflag);
    7. $test=mysubstr ("Cdb_account_log", "_");
    8. Echo $test;
    9. ?>

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.