This question already has answers here:
How do I get a file name from a full path with PHP?
(14 answers)
Closed 6 years ago.
How do I get only the file name instead of the path + file name?
foreach(glob('./item/*.txt') as $filename){
echo $filename;
}
Use basename($filename) to get the filename of the file. Check the documentation here: http://php.net/manual/en/function.basename.php
Related
This question already has answers here:
PHP Parse URL From Current URL
(6 answers)
Closed 3 years ago.
How can I extract path in url using php ?
example :
text input = https://drive.google.com/open?id=1OJOZBBUCa5SsmUF3UdGJCk7A4t2kAHVr
output = 1OJOZBBUCa5SsmUF3UdGJCk7A4t2kAHVr
You can use $_GET['id'].
Or $_SERVER['QUERY_STRING'] to get all the parameters.
This question already has answers here:
PHP, get file name without file extension
(18 answers)
Closed 6 years ago.
Is that possible to remove the file extension type from file name and underscore? For example: File name is MTK_USB_All_v1.0.1.zip But I want to show it as
MTK USB All v1.0.1
Ex: https://androiddatahost.com/upload/Amomp
Right now Im using
<?php echo $name; ?>
to show the file name. I also want to show the alternate name of the file without file extension and underscore.
Is that possible?
You can try this
$filename=basename($pathinfo);
$final_filename=str_replace('_','',$filename);
To Show only the Filename you can use pathinfo.
$filename = pathinfo('filename.zip', PATHINFO_FILENAME);
To replace underscore with blank space you can use str_replace();
This question already has answers here:
How to get the last dir from a path in a string
(11 answers)
Closed 6 years ago.
So I have a file path as a text variable in php:
"one/cool/file/path"
I need a php code to return "path"
By return I think you mean display...
Lets suppose you have the following path:
"one/cool/file/path"
Stored as a string in the variable:
"path"
To return it (or display it) you can just do:
echo path;
If you then go to your php in a web browser you should see your parh there!
You could achieve this using the following method:
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "\n";
Output: /www/htdocs/inc
http://php.net/manual/en/function.pathinfo.php#example-2657
This question already has answers here:
Remote file size without downloading file
(15 answers)
Closed 9 years ago.
Is it possible to get the remote file size for a list of links, get the file size for each and every one of these links from a array or .txt file?
hope that below will fit your needs
function remote_file_size($url){
$header = get_headers($url, true);
if (isset($header['Content-Length']))
return (int) $header['Content-Length'];
}
This question already has answers here:
What does a dot mean in a URL path?
(3 answers)
Closed 7 years ago.
<?php
$dit = new DirectoryIterator('.');
while ($dit->valid()) {
if (!$dit->isDot()) {
echo $dit->getFilename() . "\n";
}
$dit->next();
}
unset($dit);
?>
what does '.' parameter mean in DirectoryIterator method?
The argument tells it which directory to iterate over.
. is a relative path to "the current directory"
On every operating system . means the current directory, .. means the parent directory.