Varshyl Blog

Web Simplified….

Archive for the ‘PHP’ Category

Resize Image on the fly

Hi,

I have recieved many queries from people asking , how can they resize image in the fly using php.

Today I will explain how we can do it , but before we jump into code it has some prerequisite and constraint:

1) GD library should be installed on your server.

2) It works with only jpg and gif images.

IF you wondering how to make sure GD library is installed on your server , use the code below-

function GDCheck()
{
echo ” Status of GD support on your server: “;

// Check if the function gd_info exists (great way to know if gd is installed)
if(function_exists(”gd_info”))
{
echo “YES”;
$gd = gd_info();

// Show status of all values that might be supported(unsupported)
foreach($gd as $key => $value)
{
echo “–” . $key . “: “;
if($value)
echo “YES”;
else
echo “NO”;
}
}
else
echo “NO”;
}

GDCheck();
?>

  • 0 Comments
  • Filed under: PHP
  • Uploading Multiple Files with PHP

    Today we will see how can we write a code to upload mutilpe files, this is pretty simple. You can do it using one file or one html file and php file.

    Today will see how we can do it with a single ( please see I am not adding bells and whistles)
    // Absolute path of location where file is to be uploaded and don’t forget to have CHMOD 777 for it
    $fileDir = “absolute path to location”;
    $intuploadcount = 0;
    for ($intCount=0;$intCount<$numoffile;$intCount++)
    {
    //Check if the all the input box have data or not
    if (trim($_FILES['file']['name'][$intCount])!="")
    {
    $newfile = $file_dir.$_FILES['file']['name'][$intCount];
    move_uploaded_file($_FILES['file']['tmp_name'][$intCount], $newfile);
    $intuploadcount++;
    }
    }

    if (isset($intuploadcount)&& $intuploadcount>0)

    print “$intuploadcount files uploaded
    “;

    if (isset($intuploadcount)&& $intuploadcount>0)

    print “$intuploadcount files uploaded
    “;

    // echo “

    “;
    //for($i=0;$i<$filecount;$i++) {
    // echo "
    “;
    //}
    // echo ““;
    //echo “

    “;
    //?>
    ?>
    Doing with html and php files is simple, you just need to create form in html and instead of using ‘for’ loop to generate box, you need to make different box and then create another file ( name it ) and in action of form give the name of file..

    That;s it, it should work now.

  • 0 Comments
  • Filed under: PHP