Alternative to glob php

2019-09-29 04:29发布

I'm looking an alternative function to glob. I got this and it work perfectly.

<?php
$tipof = 'FACTURA';     
$cliente = '455928';
$files = glob("$cliente-$tipof*.pdf");
foreach ($files as $rows): ?>
    <td align="center">&nbsp;<?php echo end((explode('-', str_replace('.pdf','', $rows)))); ?> &nbsp;</td>
    <td align="center">&nbsp;<?php echo $cliente ?> &nbsp;</td>
    <td align="center">&nbsp;<?php echo "<a target=_blank href=\"".$rows."\">Ver</a>"; ?> &nbsp;</td>
    </tr>

The file is in the project folder but how can I do if the file is in a URL? for example something like this: http://192.168.0.196:8080/pdf/

in that url my file is 455928-FACTURA-A106-8694-20171019.pdf

Thanks!

标签: php
2条回答
淡お忘
2楼-- · 2019-09-29 04:47

If the files are stored on a different machine not having access to the file system of that machine, I would create some sort of end-point (PHP would be fine) and call end-point via ajax in client or get response with CURL from php server-side, depends on your app needs. end-point would expose results as json to be consumed by your script. I would not go for the ftp or other means to expose file system. Take care of CORS if used in browser.

查看更多
Emotional °昔
3楼-- · 2019-09-29 04:59

You cannot glob over HTTP. glob depends on being able to read a list of all files in a directory. HTTP has no concept of "directories" and no standardised way of enumerating parts of a path. It just deals with URLs. URLs don't even have to correspond to files in any way. The URL http://example.com/foo/bar could be backed by a file, or the web server serving this URL could just create the response on the fly based on whatever it feels like. There is no way to enumerate all possible URLs when such URLs could just be made up on the fly, hence there's no way to glob over HTTP.

Iff your web server happened to return a directory listing on the URL http://192.168.0.196:8080/pdf/, you could try parsing that.

查看更多
登录 后发表回答