Monday, 19 May 2014

PHP Check Mime Type of File - Return Information About A File

PHP Check Mime Type of File - Return Information About A File

Now a days, we are uploading files like Profile images, Video files OR excel files in our web application. 
With uploading these files there are chances some user upload the .exe file (Virus) by renaming the .exe into .jpg, which can damage website.

You might have added the extension check from javaScript as well as PHP. But this is not enough from security end because someone can upload the file after changing the extension of file( ".exe" to ".png"). In this case your security check will be failed.

What to do.
Answer is  check the Mime of file before get uploaded in your web server.

How to do this
"fileinfo" is extension which must be enabled in your php.ini. (for existence you can check  in phpinfo)
If this extension is not enabled ask your server admin, he will do this for you OR you can also do this your self (http://php.net/manual/en/fileinfo.installation.php).


After installing the fileinfo extension, use following code to get the mime type of file before get uploaded in web server.
if (function_exists("finfo_file")) {
    $finfo = finfo_open(FILEINFO_MIME_TYPE);    

    //file which you want to check the mime of the file
    $file = $_SERVER['DOCUMENT_ROOT'] . '/images/feedback.png';    //file which is going to get uploaded in web server
    try {
        $type = finfo_file($finfo,$file);        
        echo "File Type: ".$type;
    } catch (Exception $e) {
        echo $e->getMessage();
    }
} else {
    echo "'finfo_file' is Not installed";
}


When you execute above code, if will get the mime-type of file. This is directly checking the mime type of already uploaded file.
You can use $type = finfo_file($finfo,$file); for checking the file type, before using move_uploaded_file function.

Sunday, 18 May 2014

HR Interview Questions and Answers

  1. Tell me about yourself.
  2. Why should I hire you?
  3. What are your strengths and weaknesses?
  4. Why do you want to work at our company?
  5. What is the difference between confidence and over confidence?
  6. What is the difference between hard work and smart work?
  7. How do you feel about working nights and weekends?
  8. Can you work under pressure?
  9. Are you willing to relocate or travel?
  10. What are your goals?
  11. What motivates you to do good job?
  12. What makes you angry?
  13. Give me an example of your creativity.
  14. How long would you expect to work for us if hired?
  15. Are not you overqualified for this position?
  16. Describe your ideal company, location and job.
  17. What are your career options right now?
  18. Explain how would be an asset to this organization?
  19. What are your outside interests?
  20. Would you lie for the company?
  21. Who has inspired you in your life and why?
  22. What was the toughest decision you ever had to make?
  23. Have you considered starting your own business?
  24. How do you define success and how do you measure up to your own definition?
  25. If you won $10 million lottery, would you still work?
  26. Tell me something about our company.
  27. How much salary do you expect?
  28. Where do you see yourself five years from now?
  29. On a scale of one to ten, rate me as an interviewer.
  30. Do you have any questions for me?