Hey Matt,

> > /../imgs/blah.jpg should return
> > http://www.textx.com/t1/t2/imgs/blah.jpg
> > 
> > but its returning:
> > http://www.textx.com/t1/t2/t3/imgs/blah.jpg
> > 
> > and this: /../../imgs/blah.jpg
> > should return:
> http://www.textx.com/t1/imgs/blah.jpg
> > 
> > but its returning:
> > http://www.textx.com/t1/t2/imgs/blah.jpg
> > 
> > in both cases one extra level directory :-(
> > 
> > Any ideas?



> ok, I gave it a try and honestly this is probably
> over my head :) but
> here is something to try


Nope, no go...but dont worry about it, most of the PHP
gurus on the list have not replied so I guess it was
beyond them too....so where do we mere mortals have a
chance :-D

Will leave it as as for now and come back to it at a
later date i guess.

Thanks for trying.
Mag


 
> <?php
> 
> $url='http://www.textx.com/t1/t2/t3/blah.html';
> 
> function ret_url($rel_path, $base = '')
> {
>       $base_path = substr($base, 0, strpos($base,
> '/',7));
> 
>       if(substr($rel_path,0,1)=='/' &&
> strpos($rel_path,'/../') === false)
>       {  
>               return $base_path.$rel_path; 
>       }
> 
>         elseif(strpos($rel_path,'://') > 0)
>                 {  return $rel_path; }
> 
>         else {  
>               return collapse(dirname($base),$rel_path); 
>       }
> 
> return $rel_path;
> }
> 
> /* this function removes the /../ parts */
> function collapse($path,$rel_path)
> {
>       
>       $parsed = parse_url($path);
>       preg_match_all('/\/\.\./',$rel_path, $matches); 
>       if(($count = count($matches[0])) > 0) {
>               $parts = preg_split('/\//', $parsed['path'], -1,
> PREG_SPLIT_NO_EMPTY);
>               for ($i = 1;$i <= $count; $i++) {
>                       array_pop($parts);
>               }
>               $path = str_replace($parsed['path'],
> '/'.implode($parts,'/'), $path);
>       }
> 
>       $rel_path = (preg_match('/^\//',$rel_path)) ?
> $rel_path :'/'.$rel_path;
>       $path = preg_replace('/\/\.\./', '',
> $path.$rel_path);
>       
>       return $path;
> }
> 
> 
> $uris = array();
> $uris[] = '/blah.jpg';
> $uris[] ='/imgs/blah.jpg';
> $uris[] ='imgs/blah.jpg';
> $uris[] ='../imgs/blah.jpg';
> $uris[] ='/../imgs/blah.jpg';  // ## not working ##
> $uris[] ='/../../imgs/test.jpg'; // ## not working
> ##
> $uris[] ='http://some-site-blah.com/imgs/blah.jpg';
> 
> echo '<table border=1>';
> foreach($uris as $uri)
> {
> echo '<tr><td>'.htmlspecialchars($uri).'</
>
td><td>'.htmlspecialchars(ret_url($uri,$url)).'</td></tr>';
> }
> echo '</table>';
> ?>
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


=====
------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)


                
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to