note 91375 added to function.gzread
| From: | robinv12001 at yahoo dot co dot in | Date: | Tue, 09 Jun 2009 09:18:01 +0000 |
| Subject: | note 91375 added to function.gzread | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156583@lists.php.net to get a copy of this message | ||
<?php
//Using FTP Download a gzip file on current date from a remote server
//The gzip files are extracted
function parse_rawlist( $array )
{
$i=0;
foreach($array as $curraw)
{
$struc = array();
$current = preg_split("/[\s]+/",$curraw,9);
$struc['perms'] = $current[0];
$struc['number'] = $current[1];
$struc['owner'] = $current[2];
$struc['group'] = $current[3];
$struc['size'] = $current[4];
$struc['month'] = $current[5];
$struc['day'] = $current[6];
$struc['time'] = $current[7];
$struc['zfile_name'] = $current[8];
$structure[$i] = $struc;
$i++;
}
return $structure;
}
ini_set('memory_limit', '100M');
//Give FTP Information Here
//------------------------------------------------------------
$ftp_server = "test.com";
$ftp_user_name = "test";
$ftp_user_pass = "test";
//------------------------------------------------------------
//------------------------------------------------------------
$local_path = '/opt/lampp/htdocs/sample/test.gz';//Local Path
$server_path = 'outgoing/folder/';//Remote Sever Path
//------------------------------------------------------------
$conn_id = ftp_connect($ftp_server,21);
if($conn_id)
{
echo "Successfully connected";
}
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_chdir($conn_id, $server_path);//Change Current Working Directory
$file_list = ftp_rawlist($conn_id,".");
$zip_details = parse_rawlist($file_list);
set_time_limit(1000);
$curr_date = strtotime(date("F d Y"));
for($i=0;$i<count($zip_details);$i++)
{
$fname = $zip_details[$i]['zfile_name'];
$mod_date1 = $zip_details[$i]['month']."
".$zip_details[$i]['day']." ".date("Y");
$mod_date = strtotime($mod_date1);//File Modified Date
if($mod_date == $curr_date)//If modified date equals current date
{
$local_file = $fname;
$server_file = $fname;
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY))
{
echo "<br/>Successfully written to $local_file\n";
}
else
{
echo "<br/>There was a problem\n";
}
if(file_exists($local_file))
{
$fzip_size = $zip_details[$i]['size'];
$filename = $local_file;
$ext = pathinfo($filename,PATHINFO_EXTENSION);
$file_name = pathinfo($filename,PATHINFO_FILENAME);
$file_name = $file_name.".csv";
$zd = gzopen($filename, "r");
$contents = gzread($zd, $fzip_size);
$file_name = "uploads/".$file_name;
file_put_contents($file_name,addslashes($contents));
if(file_exists($file_name))
{
chmod($file_name,0755);
unlink($local_file);
}
gzclose($zd);
}
}
}
ftp_close($conn_id);
?>
----
Server IP: 59.162.86.8
Probable Submitter: 122.172.113.204
----
Manual Page -- http://www.php.net/manual/en/function.gzread.php
Edit -- https://master.php.net/note/edit/91375
Del: integrated -- https://master.php.net/note/delete/91375/integrated
Del: useless -- https://master.php.net/note/delete/91375/useless
Del: bad code -- https://master.php.net/note/delete/91375/bad+code
Del: spam -- https://master.php.net/note/delete/91375/spam
Del: non-english -- https://master.php.net/note/delete/91375/non-english
Del: in docs -- https://master.php.net/note/delete/91375/in+docs
Del: other reasons-- https://master.php.net/note/delete/91375
Reject -- https://master.php.net/note/reject/91375
Search -- https://master.php.net/manage/user-notes.php