5 Replies - 412 Views - Last Post: 31 January 2013 - 12:22 PM Rate Topic: -----

#1 JD.CoolPenguin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 05-May 12

glob() not returning anything

Posted 30 January 2013 - 10:50 AM

Okay, so this works on my website:
PHP:
<?php
$directory = "./images/featured/";
$images = glob($directory . "*.*");
?>
JS:
var imgArr = <?= json_encode($images) ?>;
then I put it in a theme on wordpress on my website, and it still worked.
The php and JS was in themes/tiu/inc/ and images in themes/tiu/images/featured/, for some reason ../ was referring to the root directory instead of up one directory so the directory variable looked like this:
$directory = "../tiu/wp-content/themes/tiu/images/featured/";

And this all worked.

This is where it stops working.
Then I went to put it on the site I've been making it for, which used a different web host.
Now it doesn't work but nothing's changed other than the web host.

I am using this to test:
var dir = "<?php echo $images[0]?>";
alert(dir);

and that returned an empty string (which it shouldn't, it should return the url for the first image in the folder).

I have noticed though, even though the folders have read permissions, they are forbidden access.
I put Options +Indexes in a .htaccess file in the images folder which made images and featured browsable but did not fix my problem.

I have tried:
  • using an absolute path
  • changing ../tiu/wp-content/themes/tiu/images/featured/ to ../images/featured/ which is how I thought it should originally be (up on directory, into images, into featured).
  • using $_SERVER('DOCUMENT_ROOT') - this filled up the array pointing to my images 'ex01.jpg' etc... but the path to it was invalid
  • using "http://www.".$_SERVER('SERVER_NAME') - this was essentially the same as using an absolute path and did not work


Anyone know what the heck is going on?

Thanks,
JD

This post has been edited by JD.CoolPenguin: 30 January 2013 - 10:54 AM


Is This A Good Question/Topic? 0
  • +

Replies To: glob() not returning anything

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,320
  • Joined: 08-August 08

Re: glob() not returning anything

Posted 30 January 2013 - 12:20 PM

It could be the php version: http://php.net/manua...nction.glob.php
or maybe you need to use chmod to set permissions.
Was This Post Helpful? 0
  • +
  • -

#3 JD.CoolPenguin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 05-May 12

Re: glob() not returning anything

Posted 30 January 2013 - 12:57 PM

Its not the PHP version, it's on 5.4, I already checked that.
And wouldn't I only need to use chmod if the folder didn't already have read permissions?

Thanks,
JD.
Was This Post Helpful? 0
  • +
  • -

#4 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: glob() not returning anything

Posted 30 January 2013 - 01:02 PM

I think I had a similar problem before. I was using FTP to upload my PHP files and checked the read/write permission with the the FTP program. The problem was that the FTP account DID have permission to read/write, but NOT the PHP file.

It's probably not your issue, but it doesn't hurt checking and allowing everything to read/write (if only for testing).
Was This Post Helpful? 0
  • +
  • -

#5 JD.CoolPenguin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 05-May 12

Re: glob() not returning anything

Posted 31 January 2013 - 03:37 AM

Thank Cbeppe, I can't actually check this as 1&1's cpanel is down at the moment for maintenance so the only access I have is via FTP, but when it's back up, I'll check.

In the meantime, is it possible that it's a setting in the php.ini file? or the .htaccess file? or some setting that only 1&1 can change?

Thanks,
JD.
Was This Post Helpful? 0
  • +
  • -

#6 Cbeppe  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 215
  • Joined: 16-September 09

Re: glob() not returning anything

Posted 31 January 2013 - 12:22 PM

I guess anything is possible, but I can't say if it's about any settings in the php.ini file. I would go in with FTP and set the permissions of all the directories (subdirectories too) that your script is making changes to to allow ALL read and writes.

I'm just blindly suggesting things here, so I doubt it will work, but it's always worth a try.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1