PHP job search book-PHP language Basic notes 3

Source: Internet
Author: User

Traverse all files and subfolders in a folder:

<?phpfunction my_dir($dir){    $files =array();    if($hand = opendir($dir)){        while(($file = readdir($hand)) != false){            if($file != ".." && $file != '.'){                if(is_dir($dir ."/" .$file)){                    $files[$file] = my_dir($dir ."/" .$file);                }else{                    $files[] = $file;                }            }        }        closedir($hand);        return $files;    }}?>

 

Obtain the content of a specified webpage:

File_get_contents ($ PATH );

 

Watermark website images:

  

1/* 2 imagefttext: write text to the image 3 imagecreatefromjpeg: introduce an image 4 */5 6 <? PHP 7 header ("Content-Type: image/JPEG"); 8 $ image = imagecreatefromjpeg ("abc.jpeg"); 9 $ imagecolor = imagecolorallocate ($ image, 40, 50 ); 10 11 $ text = "watermark text"; 12 13 $ font = "stcaiyun. TTF "; 14 15 imagefttext ($ image, 50,100, $ imagecolor, $ font, $ text); 16 17 imagejpeg ($ image); 18?>

 

Change the session storage directory:

  

 1 <?php 2     header("Content-Type:text/heml;charset=utf-8"); 3  4     if(!is_dir("sessioon")) 5         mkdir("session"); 6  7     $stringdir = realpath("session"); 8  9     session_save_path($stringdir);10 11     session_start();12 ?>

 

The website needs to upload a large file to make changes to PhP. ini:

1 file_uploads = on // The server supports file upload 2 3 upload_tmp_dir // uploads a temporary file directory 4 5 upload_max_filesize // The maximum number of files uploaded by the Server 6 7 max_execution_time // What a command can execute maximum time, the Unit is S 8 9 memory_limit // The content control allocated by a command. The unit is M10 11/* 12. Control File Upload on the client: 13 */14 15 enctype = "multipart/form-Data" // specify the form encoding data mode 16 method = "Post" // specify the data transmission mode 17 <input type =" hidden "name =" max_file_size "value =" 1000 "/> 18 // The value cannot exceed PhP. value set by the upload_max_filesize option in the ini configuration file

 

Solve the problem that the current system time output on the website does not match the current local time:

PHP uses the standard Greenwich Mean Time (Zero Time Zone) by default ).

1. Set Data. timezone = PRC, Asia/hong_kong, Asia/Shanghai, or Asia/Urumqi in PHP. ini.

These are UTC + 8.

2. In the application, use the date_default_timezone_set () function before the date and time functions to set the city.

 

Display_error:

Controls whether error/warning messages during script execution are displayed to users.

 

 

Save all error messages to the log file:

Set display_errors = off

Set log_errors = on

Change the file size as needed. log_errors_max_len = 1024

Set error_log = <FILENAME> the location and name of the log file

Use the error_log () function to save information to the specified file.

 

Magic methods in PhP5:

_ Sleep: Call this function before serialize () serializes an object.
_ Wakeup: This function is called before unserialize () is deserialized.
_ Tostring: This function is called when the object is converted to a string.
_ Construct: constructor called when an object is instantiated.
_ Destruct: destructor called when the object instance is released
_ Call: This function is called when no methods are available in the call class.
_ Get: called when you access a property that is not in a class
_ Set: called when setting the value of an attribute not included in a class
_ Isset: this parameter is called when an external isset function is called to check whether a class has an attribute.
_ Unset: called when a class attribute is deleted
_ Set_state: called when var_export is used to export the attributes and values of an object
_ Clone: called when copying an instance of a class
_ Autoload: When a class is used and the class is not loaded, it is called by the user.

  

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.