COMPUTER LANGUAGES | PHP | PHP INTERVIEW QUESTION AND ANSWERS - 08

PHP Interview Question and Answers:


31.     How to store the uploaded file to the final location?
      move_uploaded_file( string filename, string destination)

32.     How to open a file?
      <?php
$file = fopen("file.txt","r");
?>

33.     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\"";
?>

34.     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”;
?>

35.     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;
?>

No comments:

Post a Comment