arbitter Posted January 6, 2010 Share Posted January 6, 2010 So I have 2 columns, one on the left hand side with: foreach (glob('*',GLOB_ONLYDIR) as $map) { echo "<tr><td><a href='?month=$map'>$map</a></td></tr>";} So that all my maps with images (January '10, February '10,...) get shown with link as "uploads/January '10" Now some problems are with the space, as the script returns http://localhost/depypere/uploads/uploads.php?month=January instead of http://localhost/depypere/uploads/uploads.php?month=January '10 logical, but nevertheless, I tried to fix that. This goes n the right-hand column: $month = $_GET["month"]; $month .= " '10"; foreach (glob('$month/*.jpg') as $image) { echo "<center><img src='$image' style='max-width: 70%'></br>";} But that doesn't work at all... any help? Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/ Share on other sites More sharing options...
salathe Posted January 6, 2010 Share Posted January 6, 2010 foreach (glob('*',GLOB_ONLYDIR) as $map) { $qmap = urlencode($map); echo "<tr><td><a href='?month=$qmap'>$map</a></td></tr>"; } The single quote in the variable's value was causing your HTML to be broken. Values going into URLs should be urlencoded so that the constructed URL contains only URL-safe characters (and has the added bonus of fixing your HTML issue). Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-989963 Share on other sites More sharing options...
arbitter Posted January 6, 2010 Author Share Posted January 6, 2010 now the url shipped back to my form is uploads.php?month=January+'10 so that's not right eather... Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-989965 Share on other sites More sharing options...
arbitter Posted January 6, 2010 Author Share Posted January 6, 2010 Okay I so the url that goes back to my php file is still"/January+'10" (is that bad?) BUT I do get broken images in my right-column, though the images don't show, they are the right amount of broken-images... I have 10 images in my uploads/ file and I get 10 small boxes as if the files are missing... Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-989983 Share on other sites More sharing options...
laffin Posted January 6, 2010 Share Posted January 6, 2010 nope, in your processing script use urldecode. $month=urldecode($_GET['month']); Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990014 Share on other sites More sharing options...
salathe Posted January 6, 2010 Share Posted January 6, 2010 $_GET values are automatically decoded. Unless the query string contains double-encoded values, calling urldecode is not necessary. Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990025 Share on other sites More sharing options...
laffin Posted January 7, 2010 Share Posted January 7, 2010 the '+' is a sign that the url parameter is still encoded. Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990130 Share on other sites More sharing options...
salathe Posted January 7, 2010 Share Posted January 7, 2010 The OP never said that value was visible in his script or as the URL being visited. arbitter, are you still having problems and if so can you give us more precise details in order to help us help you. Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990243 Share on other sites More sharing options...
arbitter Posted January 7, 2010 Author Share Posted January 7, 2010 The problem is that the images I want do not get shown... There are boxes, the same amount as there are photo's, but it's a box as if the image is not in place, though I do get the right amount of boxes as there are images... $month = $_GET["month"]; foreach (glob($month . '/*.jpg') as $image) { echo "<center><img src='$image'></br>";} before clicking january; this part is good (if I add directory february '10 it gets shown too) After clicking january '10 url: http://localhost/depypere/uploads/uploads.php?month=January+'10 another question, how do I get jpg/jpeg/gif/pjpeg in one glob? Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990369 Share on other sites More sharing options...
arbitter Posted January 7, 2010 Author Share Posted January 7, 2010 Ok, I think to know the problem; it is echo "<img src='$image'></br>" but the $image returns "January '10" the ' in the $image breaks off the src for the image, so the images don't get displayed. How do I get around this? Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990401 Share on other sites More sharing options...
arbitter Posted January 7, 2010 Author Share Posted January 7, 2010 fixed it; echo "<img src=\"$image\"></br>" only one question, how do you put multiple formats in the glob() function? I suppose there's an easier way than glob($month./*.jpg, $month . /*.gif, .... Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990404 Share on other sites More sharing options...
salathe Posted January 7, 2010 Share Posted January 7, 2010 Look in the manual for GLOB_BRACE. Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990586 Share on other sites More sharing options...
arbitter Posted January 7, 2010 Author Share Posted January 7, 2010 GLOB_BRACE lijkt me niet te werken, hoe ik het ook draai of keer... heb andere fora onderzocht voor een polossing; ze zeggen meestal dat: glob($upload_dir."*.{gif,JPG,jpg,GIF}", GLOB_BRACE) werkt, maar bij mij precies niet... Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990593 Share on other sites More sharing options...
salathe Posted January 7, 2010 Share Posted January 7, 2010 Have you tried glob($month . '/*.{jpg,JPG,gif,GIF}', GLOB_BRACE) ? Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-990598 Share on other sites More sharing options...
arbitter Posted January 8, 2010 Author Share Posted January 8, 2010 Oh my I'm so sorry,my last reply was in Dutch in stead of english.. but that last one does work yes, don't really know why it didn't, perhaps the " or however you call that. Thanks a bunch! Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-991111 Share on other sites More sharing options...
salathe Posted January 8, 2010 Share Posted January 8, 2010 Oh my I'm so sorry,my last reply was in Dutch in stead of english.. Hehe no problem. Glad to see the problem solved. Quote Link to comment https://forums.phpfreaks.com/topic/187486-problem-with-_get-and-foreachglob/#findComment-991237 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.