Ricky55 Posted July 18, 2016 Share Posted July 18, 2016 Hi guys I'm very much a PHP noob. I only use the very basics. I have the code below that I created with the help of this forum some time back. It just generates some random images. I've just uploaded this to my new server and all I get is a blank screen. I've tried displaying errors but none seem to display. My new server has PHP version 5.3.3 and my old server was using 5.4 I think. Can you spot anything that might be causing this issue? Is it something to do with that server root? Cheers in advance, as always any help will be very much appreciated. Richard <?php $root = $_SERVER['DOCUMENT_ROOT']; $path = '/_/images/brand-logos/'; $random = 4; $images = array_filter(glob($root . $path . "*.*"), function($v){ return in_array(strtolower(pathinfo($v, PATHINFO_EXTENSION)), ["gif", "jpg", "png"]); }); shuffle($images); $randomImages = array_slice($images, 0, $random); foreach($randomImages as $v) echo "<img src='" . substr($v, strlen($root)) . "' alt='" . ucfirst(pathinfo($v, PATHINFO_FILENAME)) . " Logo'>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/ Share on other sites More sharing options...
Barand Posted July 18, 2016 Share Posted July 18, 2016 PHP 5.4.0 offers a wide range of new features: Support for traits has been added. Short array syntax has been added, e.g. $a = [1, 2, 3, 4]; or $a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];. Function array dereferencing has been added, e.g. foo()[0]. Closures now support $this. <?= is now always available, regardless of the short_open_tag php.ini option. Class member access on instantiation has been added, e.g. (new Foo)->bar(). Class::{expr}() syntax is now supported. Binary number format has been added, e.g. 0b001001101. Improved parse error messages and improved incompatible arguments warnings. The session extension can now track the upload progress of files. Built-in development web server in CLI mode. Change the ["gif", "jpg", "png"] to array("gif", "jpg", "png") Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534596 Share on other sites More sharing options...
Jacques1 Posted July 18, 2016 Share Posted July 18, 2016 PHP 5.3 was abandoned years ago and doesn't even receive security updates. Either get your hoster install a current PHP version (5.6 or at least 5.5), or get a new hoster. In this particular case, I suspect it's the short array syntax. But like I said, there are much more serious problems. PHP 5.3 is dead. Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534597 Share on other sites More sharing options...
Ricky55 Posted July 18, 2016 Author Share Posted July 18, 2016 (edited) oh I didn't realise it was an issue. I thought it sounded recent 5.3 to 5.4. Its my server actually so i better get that sorted. That worked by the way guys thanks very much. I just want to say that I find this the best forum I have use / used. You are all sound guys and are super quick and super helpful. Brilliant! Thanks Richard Edited July 18, 2016 by Ricky55 1 Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534600 Share on other sites More sharing options...
Ricky55 Posted July 18, 2016 Author Share Posted July 18, 2016 Guys just going back to the version, which would you recommend 5.5 or 5.6? A lot of my websites are wordpress if that has any bearing? Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534601 Share on other sites More sharing options...
benanamen Posted July 18, 2016 Share Posted July 18, 2016 5.6 minimum Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534607 Share on other sites More sharing options...
Jacques1 Posted July 18, 2016 Share Posted July 18, 2016 PHP: Supported Versions Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534610 Share on other sites More sharing options...
Zane Posted July 21, 2016 Share Posted July 21, 2016 There's really no reason to grab all the files with PHP and then loop through them and do exclusions with PHP again. Just add your restrictions to the glob() call, and then you'll have only your image files. glob($root . $path . "*.{jpg,png,gif}", GLOB_BRACE); And yea, absolutely, get PHP 5.6+. Why live in the past? Looking in the manual, there doesn't appear to even be a v5.3.3, but 5.3.29 came out in 14 Aug 2014, while PHP 5.6.22 came out in 26 May 2016 Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534757 Share on other sites More sharing options...
NotionCommotion Posted July 22, 2016 Share Posted July 22, 2016 PHP: Supported Versions What happened to PHP 6? Is PHP 7 ready? Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534812 Share on other sites More sharing options...
cyberRobot Posted July 22, 2016 Share Posted July 22, 2016 What happened to PHP 6? Is PHP 7 ready? I was wondering that myself. Apparently there was a 6, but they ended up going a different direction. More information can be found here: https://wiki.php.net/rfc/php6 Quote Link to comment https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/#findComment-1534839 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.