Showing posts with label Php Hint. Show all posts
Showing posts with label Php Hint. Show all posts
Saturday, July 14, 2012
Tuesday, May 22, 2012
File Syntax in php
by Unknown
file_exists($path) - file is exist or not unlink($path) -To remove files is_dir($path) - current path is directory or not mkdir($path) -To create new directory rmdir($path) -To remove directory copy($path)- copy files from one to another dirctory
Saturday, March 31, 2012
Zip And Unzip File Using php
by Unknown
Create Zip Files Using PHP
SourceCode $zip=new ZipArchive(); $destination=DIRDetails."/filename.zip"; if($zip->open($destination,ZIPARCHIVE::CREATE) !== true) { return false; } foreach($doclist as $thefile) { $random=rand(11111,99999); $filename=$random.$thefile; $zip->addFile($thefile->tempname,$filename); } $zip->close();
Extract Zip Files Using PHP
SourceCode $filename='filename'; $zipfile=DirDetails."/filename.zip"; $zip = zip_open($zipfile); $extract=DirDetails."/newfolder"; if ($zip) { if(!is_dir($extract)) mkdir($extract); while ($zip_entry = zip_read($zip)) { // if(zip_entry_name($zip_entry)==$filename) //if you need any specified file use this condition { $fp = fopen($extract."/".zip_entry_name($zip_entry), "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp,"$buf"); zip_entry_close($zip_entry); fclose($fp); break; } } } zip_close($zip); }
Download Zip Files Using PHP
SourceCode public function downloadfinal($docid,$docname) { $filename=Dirdetails"filename.zip"; if(file_exists($filename)){ $path_parts = pathinfo($filename); $ext = strtolower($path_parts["extension"]); switch ($ext) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } $newpath=$extract.'/'.$filename; header("Pragma: public"); header("Content-Type: application/$ctype"); header("Content-Disposition: inline; filename=$docname"); header('Content-Length: '.filesize($filename)); header("Accept Ranges: bytes"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); readfile("$filename"); } else { echo "error"; } }
Delete Zip Files Using PHP
SourceCode public function actionDeletefile($id,$fileid) { $path=Dirdetails"filename.zip"; $zip = new ZipArchive; if ($zip->open($path) === TRUE) { $zip->deleteName($dfilename); $update=Files::model()->updateAll(array( 'status' => 0 ), 'FileID ='.$id); } else { $error='failed'; } $zip->close(); } else { $error="All Files Are Deletee "; } }