PHP Interview Question and Answers

31. How to store the uploaded file to the final location?
  move_uploaded_file( string filename, string destination)
 
Your Name Your Email-ID
Your Answer
32. What type of headers have to be added in the mail function to attach a file?
  <?php
$boundary = '--' . md5( uniqid ( rand() ) );
$headers = "From: \"Me\"\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";

?>
 
Your Name Your Email-ID
Your Answer
33. How can we find the number of rows in a result set using php?
  <?php
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo “$num_rows rows found”;
?>
 
Your Name Your Email-ID
Your Answer
34. How can we know the number of days between two given dates using php?
  <?php
$tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
echo ($tomorrow-$lastmonth)/86400;
?>
 
Your Name Your Email-ID
Your Answer
35. How to open a file?
  <?php
$file = fopen("file.txt","r");
?>
 
Your Name Your Email-ID
Your Answer