A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. Submit a Pull Request Report a Bug. Parameters filename Name of the file to read. Return Values The function returns the read data or false on failure.
It might be useful to have a version of the function basename working with arrays too. Here is a quick way of fetching only the filename without extension regardless of what suffix the file has. What if you need to handle file uploads from MS IE?
There is a problem reading non-Latin characters in the file name if the locale is not configured correctly. If you still get strange results when downloading especially in IE , make sure that the PHP output compression is disabled, as well as any server compression sometimes the server inadvertently applies compression on the output produced by the PHP script.
Historically it had some performance issues and while the documentation claims there are no memory problems, real-life scenarios beg to differ — output buffering and other subtle things. Regardless, if you need byte ranges support, you still have to output the old-fashioned way. You just output a header and the module takes care of the rest.
This is the source of many seemingly obscure errors. If you have output buffering, the file will not be sent to the user in chunks but only at the end of the script.
At the start of your script, after checking the file if it exists, etc. Be aware that multiple ranges can be specified e. If the range is not valid, you must output. Do not try to guess or fix the range s as it may result in corrupted downloads, which are more dangerous than failed ones.
Many developers forget to send the code or the Accept-Ranges. Yet others forget that when you send a range, the Content-Length must match the length of the range rather than the size of the whole file. You can output the file using the method described above, skipping until the start of the range and delivering the length of the range.
I did my best to provide only accurate information. It would be truly sad for me if an article about avoiding common PHP errors contained errors itself. Learn more. Asked 10 years, 5 months ago. Active 3 years, 4 months ago. Viewed 8k times. I want to get the file name from a URL. But the problem is it's not ending with an extension.
Improve this question. Ajmal Salim Ajmal Salim 3, 2 2 gold badges 31 31 silver badges 39 39 bronze badges. Add a comment. Active Oldest Votes.
Improve this answer. Brad Christie Brad Christie
0コメント