BluApple Posted April 29 Share Posted April 29 I'm stuck on this code: <div class="gallery"><?php $images = glob(FOLDER A); foreach ($images as $i) { printf("<img src='FOLDER A...'>"); } ?></div> https://code-boxx.com/simple-php-image-gallery/ What needs to be replaced in "FOLDER A" do I need forward slashes? ("/") Tutorial here: https://code-boxx.com/simple-php-image-gallery/ Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/ Share on other sites More sharing options...
Barand Posted April 29 Share Posted April 29 <?php $images = glob("path/to/folder a/*.*"); foreach ($images as $i) { echo "<img src='$i'>"; } Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653521 Share on other sites More sharing options...
BluApple Posted April 30 Author Share Posted April 30 Thank you Barand! It still gives a blank page though. Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653549 Share on other sites More sharing options...
gizmola Posted April 30 Share Posted April 30 When people are using tutorials to try and create PHP based features, there are pitfalls, the potential for misunderstandings and the possibility of error. We need to see what your actual code is. The only exception is in the case of passwords, keys etc. Those should be replaced. So we would need to see your code and the actual path you used in your code. The operating system, hosting location etc, is also important information in many cases. It sounds like you have error turned off at present, and for development, errors need to be turned on, so you can see what they are. It looks like your code has one or more errors in it, and that is why you are getting a blank page, but if errors are turned off, you can't see what the error message is. Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653550 Share on other sites More sharing options...
BluApple Posted April 30 Author Share Posted April 30 http://inflorescence.infy.uk/tryout.php Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653552 Share on other sites More sharing options...
Solution Psycho Posted April 30 Solution Share Posted April 30 First, your two includes at the top and bottom of the page are not within correct PHP tags. Need a ? before the starting PHP. The DIV in your code is in the HTML source, but there is nothing within it. That would seem to indicate that there was no content in the $images array. I'm guessing that the path you provided to the glob function is not correct. Where is the 'photography' folder in relation to where the php file is being executed? Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653555 Share on other sites More sharing options...
BluApple Posted May 1 Author Share Posted May 1 The file is in the main folder where to upload the website. Let me try to use the correct inclusief code. That might help. I'll get back as soon as i've tried that. Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653569 Share on other sites More sharing options...
BluApple Posted May 1 Author Share Posted May 1 (edited) Adding question marks helped! Silly me! 😧 Using barands code displays all picures on the smae page while i'm trying to create a folder. Http://inflorescence.infy.uk/tryout.php Edited May 1 by BluApple Forgot link Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653570 Share on other sites More sharing options...
Suyadi Posted May 1 Share Posted May 1 HI, you can try to use glob() with the __DIR__ constant. For example: $currentDir = __DIR__; // this is your current directory So, if you want to scan images inside your sub-directory, let's say the 'gallery' directory, just do: $subDirectory = 'gallery'; $images = glob($currentDir . '/' . $subDirectory . '/*.{jpg,jpeg,gif,png,bmp,webp}', GLOB_BRACE); Check the result: print_r($images); Quote Link to comment https://forums.phpfreaks.com/topic/327568-trying-to-use-glob-function-to-create-gallery/#findComment-1653574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.