How to view all files in a directory using php.
With PHP version 5.0 and higher, you can apply a function called dir_scan() to return all the filenames in a directory. $dir = ‘dir_scan_test/’; $files1 = scandir($dir); print_r($files1); The list of filenames will be in an array. With PHP version 4.0 and lower, you have to use opendir($path) function to retrieve a list of files So, compared to PHP4, applying PHP5 codes will be much cleaner and therefore your scripts will be executed faster.
How to send email to SMS or MMS
Each phone carrier has its own hostname. To send a text message via email, you’ll need to use a SMS or MMS to SMTP Outgoing email gateway. Just substitute a 10-digit cell number for ‘number’ for each carrier below: AT&T: number@txt.att.net (SMS), number@mms.att.net (MMS) T-Mobile: number@tmomail.net (SMS & MMS) Verizon: number@vtext.com (SMS), number@vzwpix.com (MMS) Sprint: number@messaging.sprintpcs.com (SMS), number@pm.sprint.com (MMS) XFinity Mobile: number@vtext.com (SMS), number@mypixmessages.com (MMS) Virgin Mobile: number@vmobl.com (SMS), number@vmpix.com (MMS) Tracfone: number@mmst5.tracfone.com (MMS) Metro PCS: number@mymetropcs.com (SMS & MMS) Boost Mobile: number@sms.myboostmobile.com (SMS), number@myboostmobile.com…
Creating a directory in php
If your website is shared on *nix server, a directory created through mkdir() will not be assigned to you, but to the user that your host’s server or php process is running under, usually ”apache’ or ‘httpd’. In practice, this means that you can create directories, even add files to them, but you can’t delete the directory or its contents nor change permissions to a directory. It is therefore advised to create directories through PHP’s FTP API using PHP function. This is a function I…
Tips for PHP Developers
I have 3 different servers with 3 different environment settings (2 Windows servers and 1 Linux server). So every time I moved my files from 1 server to another, it’s broken because database credentials or file systems are different. Therefore, I come up with the environment check before any next logic is in place. $env_check = getenv(‘windir’); This line will output ‘C:\WINDOWS’ if your codes are on Windows server. And empty if it’s on Linux. Now I can use condition to control the different credentials…
How to send JSON string via POST in PHP
Some modern web services and APIs that requires API consumers to send JSON via a POST request. Here’s how you would program to do such task. Once we’ve got the response from the API Provider, we can decode the JSON back to an array using json_decode() function, so that PHP can process or display to client easily.