Breaking News
Home / Web / PHP / PHP Snippets

PHP Snippets

Howto disable MAMP PHP script cache?

Mamp

MAMP 2.2 uses OPCache to cache PHP scripts. So if you make a change to your PHP script, and execute the script in the browser, you will not see your change right away. Looking at the OPCache configuration in MAMP (as defined in php.ini), the cache timeout interval is set …

Read More »

How to allow PHP to upload larger file size (audio etc.)?

The following parameters can to be changed in php.ini in order to allow upload of larger files. ini_set(‘upload_max_filesize’, ’20M’); ini_set(‘post_max_size’, ’20M’); ini_set(‘max_input_time’, 300); ini_set(‘max_execution_time’, 300); The first two parameters are related to max size in MB of the uploaded file and the second two are related to how much execution …

Read More »

How to display PHP setup and environment variables?

In order to display PHP setup, configuration and environmental variables simply create a php page and execute the phpinfo command. It will display all the relevant information about PHP as output in the browser or in command line. Ex. in info.jsp<?php // Show all information, defaults to INFO_ALLphpinfo();  ?> The …

Read More »

How to list files in a directory in PHP?

<?php if ($handle = opendir(‘/path/to/directory’)) {     echo "Directory handle: $handlen";     echo "Entries:n";     /* This is the correct way to loop over the directory. */     while (false !== ($entry = readdir($handle))) {         echo "$entryn";     }     …

Read More »

How to rename file in PHP?

If you want to rename a file in PHP you can use the rename function. The syntax of the rename function is same as that of the UNIX mv(move) command. The general syntax is: rename(‘/pathA/old_file_name’, ‘/pathB/new_file_name’); e.g. rename(‘/tmp/data.log’, ‘/tmp/data1.log’); [pb_builder]

Read More »
Advertisment ad adsense adlogger