

Please check out the tutorial on regular expressions to learn the regular expressions in details. ), for example, it allows the file names such as kites.jpg or Kites.jpg, but do not allow kites.jpg. The regular expression in the above example ( line no-8) will simply not allow those files whose name starts or ends with a dot character (.

Similarly, you can force download other files formats like word doc, pdf files, etc. Here's the complete code of "download.php" file, which force image download. Also, we've used PHP urlencode() function to encode the image file names so that it can be safely passed as URL parameter, because file names may contain URL unsafe characters. Syntax is similar to HTML you can use echo to print the image but the total HTML must be present inside the PHP tags. If you see the above example code carefully, you'll find the download link pints to a "download.php" file, the URL also contains image file name as a query string. You can insert an image in PHP file by using HTML tags.
