Frank Vèssia Posted September 12, 2011 Share Posted September 12, 2011 I'm noticing a strange behavior of the image->url property. I call a php file from jquery that display an image and a message so i have to put my php file outside the /site/ dir, but when i call $image->url it returns /my-external-dir/site/assets/file/etc... <? require_once('../index.php'); $messages=$wire->pages->find("template=wallmessage,limit=20,sort=-created"); foreach ($messages as $message){ $username = $message->parent->parent->name; $profilephoto = $message->parent->parent->profilephoto->eq(0)->size(60,60); echo "<p><img src='http://{$_SERVER['HTTP_HOST']}{$profilephoto->url}' /><div><a href='/profilo/{$username}'>{$username}</a></div><div>{$message->wallmessage}</div></p>"; } ?> Link to comment Share on other sites More sharing options...
Soma Posted September 12, 2011 Share Posted September 12, 2011 Don't know why it is so. But Ryan certainly could tell you what's up with this. You could alternatively put the file in the root, this would work. Or if you got it in a folder in the root you could filter out the additional path segment. Simple as that: $path = str_replace('/myfolder','',$img->url); Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 12, 2011 Author Share Posted September 12, 2011 i can surely use str_replace but it's not a nice solution, i will wait Ryan Link to comment Share on other sites More sharing options...
ryan Posted September 12, 2011 Share Posted September 12, 2011 Sevarf2, I don't think I understand. Can you post what the expected output is in addition to the output you are getting? Or if you have a live link I can click on to see what it's doing, even better. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 12, 2011 Author Share Posted September 12, 2011 The correct path must be /site/assets/etc... but i have /process/site/assets/etc.. /process/ is the external folder where is my php file called by jquery. Link to comment Share on other sites More sharing options...
ryan Posted September 12, 2011 Share Posted September 12, 2011 Is your site running off a subdirectory called /process/ ? Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 12, 2011 Author Share Posted September 12, 2011 Not, my site is running in root but i put this file outside because i tried (using jquery) to call it from inside some pw folders but i always get "file not found". Link to comment Share on other sites More sharing options...
ryan Posted September 12, 2011 Share Posted September 12, 2011 I see what you mean. I can duplicate here too. I will work on this and post a fix shortly. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 12, 2011 Author Share Posted September 12, 2011 thank you Link to comment Share on other sites More sharing options...
ryan Posted September 12, 2011 Share Posted September 12, 2011 Okay I think I've got it fixed. You'll want to grab the latest P21 commit, or if you prefer just the /index.php file from it. Thanks for finding this issue. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted September 12, 2011 Author Share Posted September 12, 2011 Thank you so much. You are always fast ;D Link to comment Share on other sites More sharing options...
Soma Posted September 12, 2011 Share Posted September 12, 2011 Thanks Ryan for this fix, I grabed it and still not working for me. Bootstraping from a subdirectory outside of PW dirs, it includes the subdirectory in the image url. Link to comment Share on other sites More sharing options...
ryan Posted September 13, 2011 Share Posted September 13, 2011 Soma, can you try this test: 1. Create a subdirectory off of your PW installation directory, i.e. /test/ 2. Put this file in there: /test/test.php <?php include("../index.php"); echo $wire->pages->get("/some/page/")->url; If your site is installed at root, it should say: /some/page/ If your site is installed in a subdir, it should say: /subdir/some/page/ Are you getting something different? If so, what's the server environment? If you have phpinfo output that you want to PM me a URL to, that's all I would need to see. Also, double check that your /index.php is the latest version from yesterday (which is where this change was made). Very often when people (at least me) update their PW install, they just replace the /wire/ dir and not the /index.php, but this is one case where you'd need to replace the /index.php in order for it to work. Thanks, Ryan Link to comment Share on other sites More sharing options...
Soma Posted September 13, 2011 Share Posted September 13, 2011 Ok I got it on local server. Normal install, latest version (with latest inde.php) I create a strap.php in myfolder like: http://pw2.ch/myfolder/strap.php Code in strap.php: <?php include('../index.php'); $p = $wire->pages->get("/about/")->children->first(); foreach($p->images as $img){ echo "<img src='{$img->url}'/>"; } ?> Output code is: <img src='/myfolder/site/assets/files/1002/p1000832.jpg'/><img src='/myfolder/site/assets/files/1002/p1000840.jpg'/><img src='/myfolder/site/assets/files/1002/p1000835.jpg'/><img src='/myfolder/site/assets/files/1002/p1000176.jpg'/><img src='/myfolder/site/assets/files/1002/p1000183.jpg'/><img src='/myfolder/site/assets/files/1002/p1000184.jpg'/><img src='/myfolder/site/assets/files/1002/p1000185.jpg'/><img src='/myfolder/site/assets/files/1002/p1000186.jpg'/><img I sent you the phpinfo in a PM. Thanks Link to comment Share on other sites More sharing options...
ryan Posted September 13, 2011 Share Posted September 13, 2011 Thanks for sending that. Can you try this in your strap.php and tell me what the output is? <?php include("../index.php"); echo "<pre>"; echo $_SERVER['SCRIPT_FILENAME'] . "\n"; echo __FILE__ . "\n"; Here is the output on mine for instance (two of the same lines): /Applications/MAMP/htdocs/skyuser/test/index.php /Applications/MAMP/htdocs/skyuser/test/index.php I'm guessing yours are different and we may have to use realpath(). So if they are different, try this and let me know if that does it? <?php include("../index.php"); echo "<pre>"; echo realpath($_SERVER['SCRIPT_FILENAME']) . "\n"; echo realpath(__FILE__) . "\n"; Thanks for your help testing this. Link to comment Share on other sites More sharing options...
Soma Posted September 13, 2011 Share Posted September 13, 2011 yes my output is: /Applications/XAMPP/htdocs/pw2.ch/myfolder/strap.php /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/myfolder/strap.php realpath is: /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/myfolder/strap.php /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/myfolder/strap.php already seen (i'm fast ) Link to comment Share on other sites More sharing options...
ryan Posted September 13, 2011 Share Posted September 13, 2011 I just updated my original message, wondering if realpath() fixes it. Not sure it'll tell you my message was updated, so you may have to click back to page 1. Link to comment Share on other sites More sharing options...
ryan Posted September 13, 2011 Share Posted September 13, 2011 Okay cool so it looks like realpath fixes it. I'll make the update and commit it. Thanks! Link to comment Share on other sites More sharing options...
ryan Posted September 13, 2011 Share Posted September 13, 2011 Soma I was wondering if you could try out this /index.php file attached and let me know if it fixes it on your end? Since I don't have an example like yours to test from I just wanted to double check before committing. Thanks, Ryan index.php.txt Link to comment Share on other sites More sharing options...
Soma Posted September 13, 2011 Share Posted September 13, 2011 Ok, just tested and works great. Images show up Link to comment Share on other sites More sharing options...
ryan Posted September 13, 2011 Share Posted September 13, 2011 Great! thanks for testing, I will commit. Link to comment Share on other sites More sharing options...
Soma Posted September 13, 2011 Share Posted September 13, 2011 Damn, we're fast. Gotta love social coding... Link to comment Share on other sites More sharing options...
landitus Posted February 9, 2012 Share Posted February 9, 2012 Hi all! I didn't know wether to do a new post or not, because it is closely related to the above. I've been using ProcessWire 2.2 boostrapped into Codeigniter quite succesfully, until this. I am using PW as the backend and CI as the router and front end. So PW is inside the /pw/ directory in the root. In this case I am calling some PW code directly inside a CI view. I am requesting some images from an image field and the url returned is incomplete. The rest of the fields return ok. When using image_field->url, I get "/site/assets/files/1110/" without the image name or the extension. Then I prefixed the real base url to get the correct beginning (http://www.sitename.com). After that, I tried to call the image name and ext manually with $banner->image->name and$banner->image->ext but they return nothing. Exploring the $banner variable with var_dump i found the name under "basename" but not the extension. Also, maybe worth noting: I see a lot of "protected" strings inside the var_dump (don't know if that's normal). I know that there's some complexity in what I'm doing but I think there's something weird o I'm doing something wrong. Or maybe I am messing with something, right? This is the full call. Note that $pw_url adds the parent's path to where PW is nested (http://www.sitename.com). $banners_destacados = wire('pages')->get('/home/destacados/')->children('limit=3'); foreach ($banners_destacados as $banner) { echo "<div class='entrada'>". "<h3><a href='{$banner->pastilla_link}'>{$banner->title}</a></h3>". "<a class='img' href='{$banner->url}'><img src='{$banner->pastilla_imagen->url}' alt='{$banner->title}' /></a>". "<p class='description'>{$banner->pastilla_descripcion}</p>". "</div>"; print($banner->pastilla_imagen->name); } What can I do? Link to comment Share on other sites More sharing options...
Pete Posted February 9, 2012 Share Posted February 9, 2012 I think it's possible that you may not have limited the image field to only have one entry (or it might apply wither way) but try: image_field->first()->url Link to comment Share on other sites More sharing options...
ryan Posted February 9, 2012 Share Posted February 9, 2012 When using image_field->url, I get "/site/assets/files/1110/" without the image name or the extension. I agree with Pete. This sounds like you are accessing type 'Pageimages' rather than type 'Pageimage' (singular). Since you are bootstrapping ProcessWire, output formatting is going to be off. One of the side effects of that is that all image fields are treated the same (as arrays of images) rather than single images. Since you are using ProcessWire's data for output in this case, I suggest adding a single call to this before you retrieve any pages from PW: wire('pages')->setOutputFormatting(true); That will turn it on for all anything returned from the $pages API var. Or you can do it for just one page, like your banner $page: $banner->setOutputFormatting(true); Turning outputFormatting on will ensure you get the correct behavior for output. And if your image field is set to hold max 1 image, then it'll also ensure you only get that when accessing $banner->pastilla_imagen. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now