BluApple Posted Tuesday at 12:12 PM Share Posted Tuesday at 12:12 PM 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 Tuesday at 03:57 PM Share Posted Tuesday at 03:57 PM <?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 yesterday at 02:25 PM Author Share Posted yesterday at 02:25 PM 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 yesterday at 02:47 PM Share Posted yesterday at 02:47 PM 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 yesterday at 03:28 PM Author Share Posted yesterday at 03:28 PM 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...
Psycho Posted yesterday at 08:19 PM Share Posted yesterday at 08:19 PM 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 10 hours ago Author Share Posted 10 hours ago 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 9 hours ago Author Share Posted 9 hours ago (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 9 hours ago 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 7 hours ago Share Posted 7 hours ago 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.