Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by rgb192
at 2024-11-18 08:02:36
Point:500 Replies:5 POST_ID:828808USER_ID:11487
Topic:
PHP Scripting Language;;
Using php, I want to list all the filenames in a folder as hyperlinks
folder
<a href="file1.wmv" target="_blank">file1.wmv</a>
<a href="file2.wmv" target="_blank">file2.wmv</a>
<a href="file3.wmv" target="_blank">file3.wmv</a>
folder
<a href="file1.wmv" target="_blank">file1.wmv</a>
<a href="file2.wmv" target="_blank">file2.wmv</a>
<a href="file3.wmv" target="_blank">file3.wmv</a>
<?php$folder = '.';$files = scandir($folder);foreach ($files as $file): printf("<p><a href='%s' target='_blank'>%s</p>",urlencode($file), $file);endforeach;?> 1:2:3:4:5:6:7:8:
I want code that is outside the folder.
www/file.php
www/folder/file1.wmv
www/folder/file2.wmv
www/folder/file3.wmv
the problem is that the links are
www/file1.wmv
www/file2.wmv
www/file3.wmv
which do not contain the wmv files because the wmv files are in the folder
I want
www/folder/file1.wmv
www/folder/file2.wmv
www/folder/file3.wmv
Expert: Ray Paseur replied at 2024-11-22 07:05:41
Instead of using slashes, you want to use the context-aware predefined PHP constant:
DIRECTORY_SEPARATOR
If you find that you don't want to type that much when you're doing a lot of file system work, you can do something like this:
define('DS', DIRECTORY_SEPARATOR);
DIRECTORY_SEPARATOR
If you find that you don't want to type that much when you're doing a lot of file system work, you can do something like this:
define('DS', DIRECTORY_SEPARATOR);
Author: rgb192 replied at 2024-11-22 06:59:49
Duncanb7 had slashes that change direction in windows
C:UsersAcerDocumentsNuSphere PhpEDProjects/array.php
and not proper href in linux
/home/content/27/89397/html/folder/001.Welcome.f4v
But I can not find errors in Ray's code
Thanks both.
C:UsersAcerDocumentsNuSphere PhpEDProjects/array.php
and not proper href in linux
/home/content/27/89397/html/folder/001.Welcome.f4v
But I can not find errors in Ray's code
Thanks both.
Accepted Solution
Expert: Ray Paseur replied at 2024-11-18 08:51:24
450 points EXCELLENT
Obviously I am not going to leave this on my server, but you can install it and test it for yourself. A sensible design might collect the list of directories and create a table with radio buttons to facilitate the client choice of the directory. HTH, ~Ray
<?php // RAY_temp_rgb192.phperror_reporting(E_ALL);// http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28297125.html// http://www.php.net/manual/en/class.directoryiterator.php#88459// PUT THIS SCRIPT IN THE WEB ROOT DIRECTORYclearstatcache();// IF THERE IS A GET-METHOD REQUEST$dir = !empty($_GET['dir']) ? $_GET['dir'] : NULL;if ($dir){ $arr = scandir($dir); $hed = '<h3>' . $dir . '</h3>' . PHP_EOL; $dir .= DIRECTORY_SEPARATOR;}else{ $arr = scandir(getcwd()); $hed = '<h3>WEB ROOT</h3>' . PHP_EOL;}foreach ($arr as $file){ if ($file == '.') continue; if ($file == '..') continue; $url = $dir . $file; // SEE http://php.net/manual/en/function.is-file.php#107403 if (!is_dir($url)) $links[] = '<a target="_blank" href="' . $url . '">' . $file . '</a>' . PHP_EOL;}// SHOW THE LINKSecho $hed;foreach ($links as $link){ echo "<br>$link";}// A FORM TO GET THE NAME OF THE DIRECTORY$form = <<<EOD<form>Directory: <input name="dir" /></form>EOD;echo $form; 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:
Assisted Solution
Expert: duncanb7 replied at 2024-11-18 08:33:26
50 points EXCELLENT
you can use dirname(__FILE__) to display your existing full path name
and you change it around for your expect for $file
Hope it will help ;
and you change it around for your expect for $file
Hope it will help ;
<?phpchdir(dirname(__FILE__));echo dirname(__FILE__)."==x=";$folder = '.';$files = scandir($folder);foreach ($files as $file){$file=dirname(__FILE__)."/".$file; printf("<p><a href='%s' target='_blank'>%s</p>",urlencode($file), $file);}?> 1:2:3:4:5:6:7:8:9:10:11:
Expert: duncanb7 replied at 2024-11-18 08:28:36
Is it that what you want ?
<?php$folder = '.';$files = scandir($folder);foreach ($files as $file){$file="www/folder/".$file; printf("<p><a href='%s' target='_blank'>%s</p>",urlencode($file), $file);}?> 1:2:3:4:5:6:7:8:9: