Friday 29 July 2011

Why Files are not Uploading to server

A file upload form that’s been working for a long time, suddenly fails. No file uploads work on the entire apache installation. Checking the drive space in the /tmp folder, even though 85MB are left, freeing up space reveals that if there isn’t a lot of free space left for /tmp, the $_FILES array just goes empty without further explanation. No useful error messages, or anything.

Freeing up space for /tmp solves the problem effectively.
Update: Since so many commenters have posted other problems that cause similar effects, here is a quick summary of potential issues that you should check:
  1. Check php.ini for file_uploads = On, post_max_size, and upload_max_file_size. Make sure you’re editing the correct php.ini – use phpinfo() to verify your settings. Make sure you don’t mispell the directives as 8MB instead of the expected 8M!
  2. Make sure your FORM tag has the enctype="multipart/form-data" attribute. No other tag will work, it has to be your FORM tag. Double check that multipart/form-data is surrounded by STRAIGHT QUOTES, not smart quotes pasted in from Word OR from a website blog (WordPress converts straight quotes to angle quotes!). If you have multiple forms on the page, make sure they both have this attribute. Type them in manually, or try straight single quotes typed in manually.
  3. Do not use javascript to disable your form file input field on form submission!

  4. Make sure your directory has read+write permissions set for the tmp and upload directories.
  5. Make sure your FORM tag has method="POST". GET requests do not support multipart/form-data uploads.
  6. Make sure your file destination and tmp/upload directories do not have spaces in them.
  7. Make sure all FORMs on your page have /FORM close tags.
  8. Make sure your file input tag has a NAME attribute. An ID attribute is NOT sufficient! ID attributes are for use in the DOM, not for POST payloads.

Saturday 16 July 2011

How To Create Calander in PHP

<?php
//ini_set('date.timezone','UTC');

/* ***  Event Calander *******
        Developed By Webmaster
        Server should have date.timezone equals to UTC at php.ini
        else calander will not generate
*/
        //URL is like   http://mysite/test/eventcalander.php?stat=1
        /*
            $_GET['stat']; status coming vai POST or get method from URL
            0-Generate previous month ,1- Generate current month, 2- Generate next month
        */
$stat = $_GET['stat'];
$nmonth = $_GET['nmonth'];
$nyear = $_GET['nyear'];
        // *** $nmonth,$nyear will show numeric value of month,year whose Calander is showing currently at page
if($stat=="")
    $stat=1; //by default current month as status
if($nmonth=="")
    $nmonth = date('n'); //by default current month's numeric value
if($nyear=="")
    $nyear = date('Y'); //by default current year's numeric value

$calander = generateCalander($stat,$nmonth,$nyear);

?>


<form method="GET" name="frmcal" id="frmcal">
<center>
<div style="padding:20px 10px 12px 10px;">
    <?php echo $calander;?>
</div>
<input type="hidden" id="stat" name="stat" value="<?php echo $stat;?>">
<input type="hidden" id="nmonth" name="nmonth">
<input type="hidden" id="nyear" name="nyear">
<!-- nmonth stores month in numeric value whose calander is showing presently showing at page
    or we can use SESSION variable if using Ajax to store the numeric value of month such
    as 1-Jan 2 for Feb or 7 for july...this is important to keep track of which month
    we are generating calander for and which we are showing right now...
-->
</form>


<?php
function generateCalander($q,$nmonth,$nyear){   
       
/* ********* Simple Event Calander in PHP ***** */
    $stat=$q;
    $str="";       
    if($stat=='1'){
            //generate calander for current month
        $today=date('d'); 
            //This gets today's date
        $date =time() ; // this show o/p 1310737041 unix timestamp for today
        $tempmonth = $nmonth;
        $tempyear = $nyear;
    }   
    else{
        //generate calander for other month
        $tempcmon = $nmonth; // month showing at present in calander in numeric value   
        $tempcyr = $nyear; // year showing at present in calander in numeric value;
        if($stat=="2"){
            //Generate Calander for Next Month
                if($tempcmon==12){
                    $tempmonth = 1; //current month is dec so next is Jan
                    $tempyear = $tempcyr + 1;
                } else{
                    $tempmonth = $tempcmon + 1;
                    $tempyear = $tempcyr;
                }
                $OtherMonthTime = mktime(0, 0, 0,$tempmonth,1, $tempyear);
       
                /* *** mktime() is same as time() and return Unix Time but time does not
                need parameters
                mktime($hr,$min,$sec,$mon,$day,$year) all numeric else E_Strict error occurs
                */
        } else{
                // Generate Calander for Previous Month
                if($tempcmon==1){
                    $tempmonth = 12; //current month is Jan so Prev is Dec
                    $tempyear = $tempcyr - 1;
                } else{
                    $tempmonth = $tempcmon - 1;
                    $tempyear = $tempcyr;
                }
                $OtherMonthTime = mktime(0, 0, 0, $tempmonth,1, $tempyear);
                /* ** $OtherMonthTime contain Unix Time like 32558941 for our required month for 1 date
                */
        }
        $date = $OtherMonthTime;
        $today=date('d');
    }   
   
    //This puts the day, month, and year in seperate variables
    $day = date('d', $date) ; //will show Day for ex say 15
    $month = date('m', $date) ; //will show month say July
    $year = date('Y', $date) ; //will show year say 2011
        //Here we generate the first day of the month
    $first_day = mktime(0,0,0,$month, 1, $year) ;        
    $title = date('F', $first_day) ; //This gets us the month name
        //Here we find out what day of the week the first day of the month falls on
    $day_of_week = date('D', $first_day) ;
         /* 
            Once we know what day of the week it falls on, we know how many blank days occure before it.
            If the first day of the week is a Sunday then it would be zero
         */
    switch($day_of_week){
         case "Sun":
            $blank = 0;
            break;
         case "Mon":
            $blank = 1;
            break;
         case "Tue":
            $blank = 2;
            break;
         case "Wed":
            $blank = 3;
            break;
         case "Thu":
            $blank = 4;
            break;
         case "Fri":
            $blank = 5;
            break;
         case "Sat":
            $blank = 6;
            break;
    }
     /*
        Here we take a closer look at the days of the month and prepare to make our calendar table.
        The first thing we do is determine what day of the week the first of the month falls.
        Once we know that, we use the switch () function to determine how many blank days we need
        in our calendar before the first day.
        Next we count the total days of the month. Now that we know how many 'blank' days we need,
        and how many total days are in the month we can start to generate our calendar.
     */
            //We then determine how many days are in the current month
    $days_in_month = cal_days_in_month(0, $month, $year);
            //Here we start building the table heads
     $prevst="0";
     $nextst="2";
     $str= '<table border="1" cellspacing="1" cellpadding="4"><tbody>';
     $str.= '<tr><td colspan="5" bgcolor="#e0d6cb" class="black_12"> '.$title.' '.$year.' </td>';
     $str.='<td bgcolor="#e0d6cb"><a href="javascript:void(0);" onclick="callcalander('.$prevst.','.$tempmonth.','.$tempyear.');">   
     <div>--</div></a></td>
     <td bgcolor="#e0d6cb"><a href="javascript:void(0);" onclick="callcalander('.$nextst.','.$tempmonth.','.$tempyear.');">
     <div>--</div></a>
     </td></tr>';
     $str.= '<tr class="black_12">
     <td width="13%" bgcolor="#e0d6cb">Sun</td>
     <td width="13%" bgcolor="#e0d6cb">Mon</td>
     <td width="13%" bgcolor="#e0d6cb">Tue</td>
     <td width="13%" bgcolor="#e0d6cb">Wed</td>
     <td width="13%" bgcolor="#e0d6cb">Thu</td>
     <td width="13%" bgcolor="#e0d6cb">Fri</td>
     <td width="13%" bgcolor="#e0d6cb">Sat</td></tr>';
            //This counts the days in the week, up to 7
     $day_count = 1;
     $str.= '<tr class="week">';
            //first we take care of those blank days
     while($blank > 0)
     {
        $str.= '<td class="blank black_12" height="25" align="center"></td>';
        $blank = $blank-1;
        $day_count++;
     }
    /*
    The first part of this code very simply echos the table tags, the month name, and the headings for the days of
    the week. Then we start a while loop. What we are doing is echoing empty table details, one for each
    blank day we count down. Once the blank days are done it stops. At the same time, our $day_count
    is going up by 1 each time through the loop. This is to keep count so that we do not try to put
    more than seven days in a week.
    */

            //sets the first day of the month to 1
    $day_num = 1;
            //count up the days, untill we've done all of them in the month
    while($day_num <= $days_in_month)
    {
         if($day_num==$today)
             $class="today black_12";
         else
             $class="black_12";

         $str.= '<td class="'.$class.'" height="25" align="center">'.$day_num.'</td>';
         $day_num++;
         $day_count++;
            //Make sure we start a new row every week
        if($day_count > 7)
        {
            $str.='</tr><tr>';
            $day_count = 1;
        }
    }
    /*
        Now we need to fill in the days of the month. We do this with another while loop,
        but this time we are counting up to the last day of the month. Each cycle echos a table detail
        with the day of the month, and it repeats until we reach the last day of the month.
        Our loop also contains a conditional statement. This checks if the days of the week have reached 7,
        the end of the week. If it has, it starts a new row,
        and resets the counter back to 1 (the first day of the week).
    */
            //Finaly we finish out the table with some blank details if needed
     while($day_count >1 && $day_count <=7)
     {
        $str.='<td></td>';
        $day_count++;
     }
    $str.='</tr></tbody></table>';
/* Calander Code Ends ****/

    return $str;
   
}
?>
<script>
function callcalander(val1,val2,val3){
    document.getElementById('stat').value=val1;
    document.getElementById('nmonth').value=val2;
    document.getElementById('nyear').value=val3;
    document.frmcal.submit();
}
</script>


download php file from following ink
http://www.keepandshare.com/doc/2989630/eventcalander-zip-july-16-2011-2-57-pm-3k?da=y

Thursday 14 July 2011

How To Create Event Calendar in PHP

<?php
/* ********* Simple Event Calander in PHP *****
** http://php.about.com/od/finishedphp1/ss/php_calendar.htm
*** with Code modified By Snyxius Developer
*/
 //This gets today's date 
$date =time () ;
 //This puts the day, month, and year in seperate variables
$day = date('d', $date) ;
$month = date('m', $date) ;
$year = date('Y', $date) ;
 //Here we generate the first day of the month 
$first_day = mktime(0,0,0,$month, 1, $year) ;
 //This gets us the month name
$title = date('F', $first_day) ;
//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day) ;
 /*  
Once we know what day of the week it falls on, we know how many blank days occure before it. 
If the first day of the week is a Sunday then it would be zero 
 */

 switch($day_of_week){
 case "Sun":
$blank = 0;
break;
 case "Mon":
$blank = 1;
break;
 case "Tue":
$blank = 2;
break;
 case "Wed":
$blank = 3;
break;
 case "Thu":
$blank = 4;
break;
 case "Fri":
$blank = 5;
break;
 case "Sat":
$blank = 6;
break;
 }
 /*
Here we take a closer look at the days of the month and prepare to make our calendar table.
The first thing we do is determine what day of the week the first of the month falls. 
Once we know that, we use the switch () function to determine how many blank days we need 
in our calendar before the first day.
Next we count the total days of the month. Now that we know how many 'blank' days we need, 
and how many total days are in the month we can start to generate our calendar.
 */
 //We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year);


//Here we start building the table heads
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr>
<td width=42>S</td>
<td width=42>M</td>
<td width=42>T</td>
<td width=42>W</td>
<td width=42>T</td>
<td width=42>F</td>
<td width=42>S</td>
</tr>";
//This counts the days in the week, up to 7
$day_count = 1;
echo "<tr>";
//first we take care of those blank days
while($blank>0)
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
/*
The first part of this code very simply echos the table tags, the month name, and the headings for the days of 
the week. Then we start a while loop. What we are doing is echoing empty table details, one for each 
blank day we count down. Once the blank days are done it stops. At the same time, our $day_count 
is going up by 1 each time through the loop. This is to keep count so that we do not try to put 
more than seven days in a week. 
*/

//sets the first day of the month to 1
$day_num = 1;
 //count up the days, untill we've done all of them in the month
while ( $day_num <= $days_in_month )
{
echo "<td> $day_num </td>";
$day_num++;
$day_count++;
//Make sure we start a new row every week
if($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
/*
Now we need to fill in the days of the month. We do this with another while loop, 
but this time we are counting up to the last day of the month. Each cycle echos a table detail 
with the day of the month, and it repeats until we reach the last day of the month.
Our loop also contains a conditional statement. This checks if the days of the week have reached 7, 
the end of the week. If it has, it starts a new row, 
and resets the counter back to 1 (the first day of the week).
*/
//Finaly we finish out the table with some blank details if needed
while ( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}
 echo "</tr></table>";

/* Calander Code Ends ****/

?>

Tuesday 12 July 2011

Storing and Displaying dates in different timezones in PHP


Situation
I want a user in, say, California to be able to post a comment that will be stored in MySQL. I then want a user in, say, Texas to be able to view the comment with the post date adjusted to his or her time zone.
Proposed Solution
Storing
  1. Run the following at the start of the application so that all date functions use UTC timezone:date_default_timezone_set('UTC');
  2. $Date = new DateTime(); to get a DateTime object with the current date and time in UTC.
  3. Use $Date->format() to get the value to insert into the datetime type column in MySQL.
Displaying
  1. Get the user's timezone information from JavaScript and store it in a cookie.
  2. Run a MySQL SELECT query to retrieve the datetime column value.
  3. $Date = new DateTime($row['time']); to instantiate a DateTime object with the stored UTC time.
  4. $Date->setTimezone(new DateTimeZone($userTimezone)); to adjust the UTC time to the user's timezone.
  5. Display using $Date->format();

Monday 11 July 2011

Rotating Banner in Javascript

 Learn how to create a banner system that rotates your banners without the user having to refresh. Using javascript you can make a nicely flowing rotating banners script that doesn't require the user to refresh at anytime, good for ad systems.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Rotating Banners</title>

<script language="Javascript" type="text/javascript">
<!-- Hide from old browsers
 var adImages = new Array("images/banner.jpg","images/banner1.jpg","images/banner2.jpg")
thisAd = 0
imgCt = adImages.length

function rotate() {
if (document.images) {
thisAd++
if (thisAd == imgCt) {
thisAd = 0
}
adBanner.src=adImages[thisAd]
setTimeout("rotate()", 3 * 1000)
}
}
// End hide script from old browsers -->
</script>
<body onload="rotate()">
<center>
<img src="images/banner1.gif" name="adBanner" alt="Ad Banner" />
</center>
</body>
</html>