The following blog entry was written by Larry Nies, president of NSC, Inc. He has been working with PHP on the IBM i since 2005, when he installed his first open-source PHP stack. The following year, he switched to the Zend Technologies PHP application server for IBM i.
During the six years I have been working with PHP on IBM i, I have seen it evolve into a sophisticated Web-application language. In 2006 one of my customers began using Zend Core and Zend Platform (from Zend Technologies) and has since moved to Zend Server.
I wrote my first application with nothing to guide me except a couple of samples that someone else wrote to run on a non-IBM i platform. For example, I was looking for an application to allow a customer’s customers to download/upload files (due to the email file size limitations). I found a UNIX open-source PHP script for FTP that was written by Edwin van Wijk. I downloaded Edwin's open-source PHP version and then decided that if I was going to change this script to work on the IBM i, I might as well have it work for Linux, Mac and Windows as well, to cover the customer’s other FTP servers.
Initially, I had to change the program to also allow public access without a login, as that was the method that my customer wanted to use. I then went about parsing the data received back from the various platforms--IBM i, Linux, Mac and Windows--when FTPed so as to provide a Windows Explorer look, similar to that which was in the original PHP script. Once I got the data stream parsed, based on the server platform, I began the task of streamlining the selection of the “FTP Hosts” using an array and a config.ini file that included all of the information needed to make the various server connections. It looked something like this:
[hosts]
;
; Variable List:
; host = Host IP or Server name
; srvname = Server Name to appear in Dropdown List
; port = Server FTP Port #
; passive = FTP Passive true/false depending on Server
; directory = Base Directory for User Login
; user = User for logging on to the FTP Server
; password = User password for logging on to the FTP Server
; adduserid = Add User ID to the Directory Path true/false
; navdelete = Ability to Delete files/folders from Navigation Menu
; navdownload = Ablility to download files from Navigation Menu
; publicaccess = Is this a PUBLIC access Y/N
;
; PublicFTP Additional Variable List:
; user = Default USER for PUBLIC Access
; password = Default PASSWORD for PUBLIC Access
;
; Note: You can have any number of Sets with information the PHP script will handle accordingly.
;== Set 1
config.params.host1="172.16.10.4"
config.params.srvname1="System i"
config.params.port1="21"
config.params.passive1="true"
config.params.directory1="/home"
config.params.user1=""
config.params.password1=""
config.params.addusrid1="true"
config.params.navdelete1="true"
config.params.navdownload1="true"
config.params.publicaccess1="N"
Now that I had my config.ini file with all of the server information, I could add as many FTP platforms that I wanted to various FTP servers. Not only does this open-source code work with IBM i but it is also cross-platform enabled.
Have any scripts you’d like to share? Please add them in the Comments section below.




I've had great fun and made plenty of valuable use with the following code Larry shared the how to some time ago and we have used the solution to easily and quickly retrieve data and format it into a CSV (excel) file. It's a little bit of code with lots of Power. In this example a login file is being displayed.
?php
// Laura A. Ubelhor
// Display login file in .CSV format
// Awesome ap to easily connect and create an excel file!
// connect to database
$host = "HOSTIBMI";
$user = 'USERID';
$pass = 'PASSWORD';
$conn = db2_connect ($host,$user,$pass);
// This code will tell the browser that this is a CSV (Excel) file.
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=VRSWebUserIDList".date("Y-m-d").".csv");
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
//Create Table Headers
echo "User Id, Password, Description, Type, Email Address \n";
// SQL statement - LIBRARY.LOGIN is IBM i library and file name
$query = "SELECT * FROM LIBRARY.LOGIN";
//Execute query
$queryexe = db2_exec($conn, $query) ;
//Fetch results
while(db2_fetch_row($queryexe)) {
$userid = db2_result($queryexe, 'RUSERID');
$password = db2_result($queryexe, 'RPASS');
$description = db2_result($queryexe, 'RDESC');
$type = db2_result($queryexe, 'RTYPE');
$email = db2_result($queryexe, 'REMAIL');
echo "$userid,$password,$description,$type,$email\n";
}
?
*in order to display the code we needed to remove the less than and greater than signs - IBMSystemsMag
Posted by: Laura Ubelhor | September 16, 2011 at 08:55 AM