Search the Community
Showing results for tags 'glob'.
-
I have the following php block that works on an existing bootstrap webpage: <?php $isos = glob('download/*.iso'); $iso = $isos[count($isos) -1]; $isoname = basename($iso); $isodown = "/".$isoname; $md5file = md5_file($iso); $pdfs = glob('download/foxcloneV*.pdf'); $pdf = $pdfs[count($pdfs) -1]; $pdfname = basename($pdf); $debs = glob('download/*.deb'); $deb = $debs[count($debs) - 1]; $debname = basename($deb);; $srcs = glob('download/*.tar.*'); $src = $srcs[count($srcs) - 1]; $srcname = ltrim($src,'download/'); ?> When I try to use it in a non-bootstrap website, it fails with the following errors: Notice: Undefined offset: -1 in /home/larry/web/test2/public_html/download.php on line 104 Warning: md5_file(): Filename cannot be empty in /home/larry/web/test2/public_html/download.php on line 106 Notice: Undefined offset: -1 in /home/larry/web/test2/public_html/download.php on line 109 Notice: Undefined offset: -1 in /home/larry/web/test2/public_html/download.php on line 113 Notice: Undefined offset: -1 in /home/larry/web/test2/public_html/download.php on line 117 Each of these failures is the line after the glob. Is the glob failing or is the syntax wrong for non-bootstrap use? Either way, my thinking is that php should behave the same regardless of what the base model for the website is. Both the bootstrap and non-bootstrap sites are running locally under apache2.4 and php7.2. Can someone provide some insight?
-
Hello I have several json files in one directory. i would like to merge them in to one. I did something like this <?php foreach (glob("../json/*.json") as $filename) { echo basename($filename) . "\n"; } $res1 = file_get_contents($filename); echo $res1; ?> But it echoes only the last (the first echo is to view all files which is not important here) Then I tried many versions of foreach inside foreach with no success. Like this: <?php foreach (glob("../json/*.json") as $filename) { foreach (file_get_contents($filename) as $a) { } } echo $a; ?> So I appreciate a little help here, thank you.
-
Hi all I am trying to display a list of images contained withina folder. I am using the following code <?php //Path to folder which contains images $dirname = $shopConfig['url'].'images/flags/'; //echo $dirname; //Use glob function to get the files //Note that we have used " * " inside this function. If you want to get only JPEG or PNG use //below line and commnent $images variable currently in use print_r(glob($dirname."*")); $images = glob($dirname."*.png"); //Display image using foreach loop foreach($images as $image){ //print the image to browser with anchor tag (Use if you want really ) echo '<a href="'.$image.'" target="_blank"><img src="'.$image.'" height="100" width="100" /></a>'; } ?> I know there are images within the folder, however when I print the array it is empty. Can anyone point out what is wrong with the code and where I have gone wrong? Thanks
-
I am running php 5.4, IIS 7.5 on WinServer 2008 R2 box. I want to retrieve all subfolder names in a directory using PHP. I can successfully perform this task IF the target folder exists on the same drive as the php code, which is on c:\. However, I need to retrieve subfolder names from the e:\ drive on the same server. I have the permissions properly set for IUSR and IIS_IUSRS (read & exe, modify) for the target and parent folders but of course I don't have those permissions all the way to the root of e:\ drive. Using scandir(), I get "Access is denied. (code: 5)" but I have tried glob() and RecursiveDirectoryIterator to no avail. I have not been able to find a solution or an example so perhaps it is not possible. Any recommendations are greatly appreciated.
-
Hey guys, i have created a php file which takes two parameters: a subdirectory path a file extension it then echos the complete path pf (glob()) all the files with that extension in the searching folder. I wanted to know the security issues involved with this and how i might use escape methods to make sure someone can't move up the directory listing and get other filename. Are there any other concerns i should have? No data is coming or going to a database however there are other php files on the server which communicate with mySQL. Thanks alot!
-
Hi I want to echo out something when I post the value of a radio button and this value matches the same name of a html file. How can I formulate my code to achieve that? What I have so far: <?php if (isset($_POST['submitradio'])) { $selected_dir = $_POST['radio1']; echo substr($selected_dir, 0, -4); echo '<img src="'.$selected_dir.'" />'; } ?> So far I get for example the name of the image(order.gif) and the image order. gif. What I now want is to formulate my code so that I can say if I have an image called "order.gif" and a file called "order.html" that I can then echo out some thing. I don't want to actually name the image or the html file. I just want to say if I have two different file types that start with the same name then I can echo out what ever. How can I do that?