Jump to content

Archived

This topic is now archived and is closed to further replies.

foucquet

PC v Laptop code problem

Recommended Posts

OK, I am developing a Wordpress theme, not getting much response fromt their support, so I thought I would ask here especially as is does not seem to be a pure Wordpress problem. Can anyone explain why this:-

 

$size = "full";

   $photos = get_children( array(
    'post_parent' => $post->ID,
    'post_status' => 'inherit',
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'order' => 'ASC',
    'orderby' => 'menu_order ID') );

   	if ($photos) {
  	$photo = array_shift($photos);
	$result = wp_get_attachment_url($photo->ID, $size);
  	}

$imgurl = $result;

$exif = exif_read_data($imgurl, 'EXIF'); //<<<<<< Line 67

$exifdata = array();
format_exif_data($exif);

 

should work on my laptop, but give me a "Warning: exif_read_data() [function.exif-read-data]: Filename cannot be empty in C:\wamp\www\wordpress\wp-content\themes\image-a-nation\index.php on line 67" on my PC?

 

I have the same version of WAMP installed on both, so this strikes me a just a little weird, and much head scratching over the weekend has not shed any light at all. Hopefully someone can save me from insanity...

Share this post


Link to post
Share on other sites

Clearly $imgurl is empty.

 

Which means that $result is also empty.

 

Which means that either $photos is empty, or wp_get_attachment_url is not working.  Figure out which it is.

 

 

 

This is how you debug things on your own.

Share this post


Link to post
Share on other sites

Clearly $imgurl is empty.

 

Which means that $result is also empty.

 

Which means that either $photos is empty, or wp_get_attachment_url is not working.  Figure out which it is.

 

 

 

This is how you debug things on your own.

 

This is how I usually debug things...

// if....
echo 'here'; // k that works


// if........
echo 'here'; // k that works


// if.......
echo 'here'; // nope, WTF?!

Share this post


Link to post
Share on other sites

If you echo "here" every time you don't know where you are.  I always:

echo __FILE__ . " at line " . __LINE__ . "<br />\n";

-Dan

Share this post


Link to post
Share on other sites

Aye, I use both echo and var_dump() when debugging, but neither of these tell me why this works on my laptop setup but not on the PC setup, surely if it works on one it should work on the other.

 

 

Clearly $imgurl is empty.

Which means that $result is also empty.

Which means that either $photos is empty, or wp_get_attachment_url is not working.  Figure out which it is.

 

I agree that this is the case with the PC, but it is not on my laptop, and I can't figure out why the PC set up is throwing this error. To make it just a little clearer, this works to pick up the exif data from each sucessive image, working Previous/Next, which is fine as long as I do not go back to the first (oldest) image; when it hits the oldest post it throws the error, at least on my PC setup.

 

Surely if it works on one then it should, in theory, work on both  :-\  :shrug:  >:(

Share this post


Link to post
Share on other sites

If it helps any I inserted -

var_dump($photo, $photos, $result, $imgurl);

below

$imgurl = $result;

- and it returned the following:-

 

$photos=

object(stdClass)[301]

  public 'ID' => int 71

  public 'post_author' => string '1' (length=1)

  public 'post_date' => string '2011-12-09 08:25:38' (length=19)

  public 'post_date_gmt' => string '2011-12-09 08:25:38' (length=19)

  public 'post_content' => string '' (length=0)

  public 'post_title' => string 'loch-linnhe-at-port-appin' (length=25)

  public 'post_excerpt' => string 'Loch Linnhe at Port Appin' (length=25)

  public 'post_status' => string 'inherit' (length=7)

  public 'comment_status' => string 'open' (length=4)

  public 'ping_status' => string 'open' (length=4)

  public 'post_password' => string '' (length=0)

  public 'post_name' => string 'loch-linnhe-at-port-appin' (length=25)

  public 'to_ping' => string '' (length=0)

  public 'pinged' => string '' (length=0)

  public 'post_modified' => string '2011-12-09 08:25:38' (length=19)

  public 'post_modified_gmt' => string '2011-12-09 08:25:38' (length=19)

  public 'post_content_filtered' => string '' (length=0)

  public 'post_parent' => int 78

  public 'guid' => string 'http://localhost/wordpress/wp-content/uploads/2011/12/loch-linnhe-at-port-appin.jpg' (length=83)

  public 'menu_order' => int 0

  public 'post_type' => string 'attachment' (length=10)

  public 'post_mime_type' => string 'image/jpeg' (length=10)

  public 'comment_count' => string '0' (length=1)

  public 'filter' => string 'raw' (length=3)

 

$photo=

array

  empty

 

$result=

string 'http://localhost/wordpress/wp-content/uploads/2011/12/loch-linnhe-at-port-appin.jpg' (length=83)

 

$imgurl=

string 'http://localhost/wordpress/wp-content/uploads/2011/12/loch-linnhe-at-port-appin.jpg' (length=83)

 

However on hitting the last image the return was the following:-

 

$photos=

null

 

$photos=

array

  empty

 

$result=

null

 

$imgurl=

null

 

everything empty.

Share this post


Link to post
Share on other sites

Ok, so then...one of your images is empty for some reason.  Why could that be?  Clearly these are different databases.  Go look at the records.

Share this post


Link to post
Share on other sites

I had a quick look and everything seems to be right, I am beginning to suspect that it is because the versions of PHP are different, 5.3.4 on the laptop and 5.3.8 on the PC. Not even going to think about all ths for the next week or so, too busy with Xmas related stuff...

Share this post


Link to post
Share on other sites

Extremely doubtful that it's due to a minor sub-version difference.

 

You have a function that returns a list.  On one machine, the last item in that list is empty.  Go into that function and figure out why.

 

Or simply wrap this whole thing in an if ( !empty() ) check.

 

-Dan

Share this post


Link to post
Share on other sites

Well, this is truly weird! Out of sheer desperation I deleted the oldest post, making the second oldest post the oldest, and it seems to have solved the problem, why I haven't a clue. All I can assume is that there is some sort of problem with the image attached to that particular post - requires some investigation.

 

I can't think why I didn't do this in the first place to test if it was a problem with the particular post or a programming problem.

 

The next step is to post the same image as the newest post and see if it throws the same error, if it does then I know it is the image, but if it doesn't then I will be even more puzzled that at present...

 

Update:-

 

Curiouser and curiouser, just posted the problem image as the newest post and it is behaving exactly how I would expect - WTF!"

Share this post


Link to post
Share on other sites

×
×
  • 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.