Showing posts with label file operations. Show all posts
Showing posts with label file operations. Show all posts

Wednesday, January 16, 2013

Upload huge files in PHP


When we try to upload huge files using PHP, we face many issues to upload. One of them might be the php_value upload_max_filesize which is by default 2M in php.ini

Still we may have other issues which we need to do fix them. Below are the steps we need to add in htaccess to fix the large file uploads.


php_value upload_max_filesize 10M
php_value post_max_size 64M
php_value max_execution_time 300


Thursday, January 3, 2013

javascript validation for file upload

Below is the article for adding javascript validation (or) jquery validation for a file upload that makes our life easier whether the file upload is a valid type or not.


if($('#upload_file').val() != '')
{
        var _validFileExtensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"]; // Can change the extensions if we need for doc type or something else
        if($('#upload_file').val() != '')
        {
            var sFileName = $('#upload_file').val();
            var blnValid = false;
            for (var j = 0; j < _validFileExtensions.length; j++)
            {
                var sCurExtension = _validFileExtensions[j];
                if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                    blnValid = true;
                    break;
                }
            }
            if(!blnValid)
            {
               alert("Sorry, " + sFileName + " is invalid, allowed extensions are: " + _validFileExtensions.join(", "));
                $('#upload_file').focus();
                return false;
            }
        }
 }

Monday, August 2, 2010

Get the Page title of a webpage using PHP

Below is the function for getting the Title of the webpage using PHP

function getMetaTitle($content){
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui";
if(preg_match($pattern, $content, $match))
return $match[1];
else
return false;
}

$url = $siteurl; //Enter the Site URL which we want to get the Page Title
$content = file_get_contents($url);
$title = getMetaTitle($content);
$tags = get_meta_tags($siteurl); // To get the meta content, description, keywords of the given URL....


$tags is a array of all meta data
To get the Meta Keywords, Description we will use the get_meta_tags which is a predefined function in PHP. To retrieve the values we need to use $tags['keywords'] for Keywords & for Description $tag['description']


 

Saturday, July 31, 2010

Check Domain availability Using PHP

How to Check Domain Availability using PHP


<?php

function checkDomainAvailability($domain_name){

$server = 'whois.crsnic.net';

// Open a socket connection to the whois server
$connection = fsockopen($server, 43);
if (!$connection) return false;

// Send the requested doman name
fputs($connection, $domain_name."\r\n");

// Read and store the server response
$response_text = ' :';
while(!feof($connection)) {
$response_text .= fgets($connection,128);
}

// Close the connection
fclose($connection);

// Check the response stream whether the domain is available
if (strpos($response_text, 'No match for')) return true;
else return false;
}


$domainname = 'anilbuddha.com';

if(checkDomainAvailability($domainname)) echo 'Domain : '.$domainname.' is Available';
else echo 'Domain : '.$domainname.' is Already Taken';

?>