Jump to content

Recommended Posts

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'>";
 
    ?>

Link to comment
https://forums.phpfreaks.com/topic/301501-new-server-doesnt-like-my-code/
Share on other sites

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")

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.

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 by Ricky55
  • Like 1

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.