Showing posts with label PHP trim. Show all posts
Showing posts with label PHP trim. Show all posts

Wednesday, 3 June 2015

PHP: Unzip a Zip File

 This code allows you to Unzip a ZIP file with PHP.
<?php   
function unzip($location,$new_location){
    if(exec("unzip $location",$arr)){
        mkdir($new_location);
        for($i = 1;$i< count($arr);$i++){
            $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
                    copy($location."/".$file,$new_location."/".$file);
                    unlink($location."/".$file);
            }
        return true;
    }
    return false;      
}
 
// usage of this code
if(unzip('ziped_files/test.zip','unziped_files/newfile')){
    echo 'Successfully unzipped!';
}else{
    echo 'Error while processing your file!';
 
}
?>

Monday, 23 February 2015

PHP: Capture the requested URI and Clean up global variables

<?php
$requestURI = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']';
echo $requestURI;
?>

This snippet is more of an example of how to convert strings to lowercase characters, and then clean them up for use in scripts, etc
<?php
$_POST["name"] = strtolower(stripslashes(trim(htmlspecialchars($_POST["name"])))); $_POST["message"] = strtolower(stripslashes(trim(htmlspecialchars($_POST["message"]))));
?>