[support] file_create_url() breaks some sites

Pierre Rineau pierre.rineau at makina-corpus.com
Fri Jul 4 15:21:59 UTC 2008


On ven, 2008-07-04 at 17:17 +0200, Pierre Rineau wrote:
> Thanks for you answer, but I think you did not answer my question. Maybe
> I did not formulate it correctly.
> 
> When I say relative path, I mean path relative to server root (without
> domain name in it), not path without the preceding "/".
> 
> Absolute URL is an URL with "http://server" and relative URL will be
> just "/". I speak of relative or absolute URL not relative or absolute
> PATH.
> 
> On ven, 2008-07-04 at 15:43 +0100, Matt Connolly wrote:
> > In either case, PUBLIC or PRIVATE, the resulting url for a file should  
> > look something like:
> > 
> > /path/to/filename
> 
> No suprises.
> 
> > Which should then use the same "http://server/" part as the rest of  
> > the site.
> > urls, generally need to be absolute so that urls can be created that  
> > will work irrespective of the setting of "Clean URLs". eg:
> > 
> > Clean URL off:
> > drupal pages are at http://server/?q=drupal/path/page  ->  the path of  
> > these will *always* be "/" since thats the path that hosts the  
> > "index.php" file.
> > 
> > Clean URL on:
> > drupal pages are at http://server/drupal/path/page -> your browser  
> > thinks the path of the file is in a directory /drupal/path/ .
> 
> With clean URL, and absolute pathes:
> --
> my file URL will be http://server/files/filename
> my path URL will be http://server/drupal/path/page
> 
> clean URL, relative:
> --
> file: /files/filename
> path: /drupal/path/page
> 
> Without clean URL, absolute:
> --
> file: http://server/files/filename
> path: http://server/index.php?q=drupal/path/page
> 
> without, relative:
> --
> file: /files/filename
> path: /index.php?q=drupal/path/page
> 
> No difference, in all cases, apache will find the file to use. URL do
> not need to carry the "http://server" since in all cases, this string is
> exactly the same, clean URL or not. Apache (or another httpd) will know
> what to rewrite or not. The only case we could absolutely need absolute
> URLs will be in case our files are on another static server (eg:
> "http:/static-server").
> 
> So relative or absolute URLs, makes no difference at all wheither it's a
> file or a drupal page the user asked.
> 
> Even better, if the file does not exists, he's got a clean 404 error.
> 
> > You can see that the setting of clean urls can change whether a  
> > relative link will work or not.
> > 
> > I think it's safe that url() defaults to making absolute urls that  
> > will work in both clean urls ON and OFF.
> 
> Absolute or relative makes no difference here. URL default is FALSE
> (relative) anyway.
> 
> Absolute is necessary only if you have to link content from another
> httpd on another box (or another virtual host).
> 
> > 
> > It also sounds like you might have a local network problem.
> 
> This is not a problem, this a feature, we have a quite complex network,
> and linking files with Drupal is the only problem we ever had with CMSs
> (we don't only use Drupal).
> 
> To finish, if we look to the default Apache rewrite rules that Drupal
> put in the .htaccess file, we have:
> 
>   RewriteCond %{REQUEST_FILENAME} !-f
>   RewriteCond %{REQUEST_FILENAME} !-d
> 
> These two lines have their importance. Apache here checks if path is not
> a real FS path neither a real file on FS.
> 
> When we link a file, we will never add the index.php?q= except maybe for
> private files, when we have to do some checks with Drupal framework.
> 
> But for public files, we never need the index.php?q=, clean url or not,
> relative path or not.
> 
> I really think this method should be able to generate relative pathes.
> If it can't, is there a workaround to do so ?

I really think this method should be able to generate relative URL <=
typo error, URL was the good word (makes no sens to say path here).
if it can't, is there a workaround to do so ?

> > -Matt
> > 
> > 
> > 
> > On 04/07/2008, at 2:21 PM, Pierre Rineau wrote:
> > 
> > > Hi
> > >
> > > I have some problèmes with the CCK image field module. This is not  
> > > because of the module, but because of the core file_create_url()  
> > > function.
> > >
> > > I explain:
> > >
> > > <?php
> > > function file_create_url($path) {
> > >  // Strip file_directory_path from $path. We only include relative  
> > > paths in urls.
> > >  if (strpos($path, file_directory_path() . '/') === 0) {
> > >    $path = trim(substr($path, strlen(file_directory_path())), '\\/');
> > >  }
> > >  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
> > >    case FILE_DOWNLOADS_PUBLIC:
> > >      return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'.  
> > > str_replace('\\', '/', $path);
> > >    case FILE_DOWNLOADS_PRIVATE:
> > >      return url('system/files/'. $path, NULL, NULL, TRUE);
> > >  }
> > > }
> > > ?>
> > >
> > > This give me an asbolute URL because of the use of $GLOBALS['url'].
> > >
> > > If we look at the url() function, we have a boolean parameter  
> > > $absolute, which is default setted to FALSE.
> > > If false is selected, , the method use base_path() as base for the  
> > > url, else it uses the global $base_url.
> > >
> > > Is this normal that drupal devs made the choice of always put  
> > > absolute URL for files ?
> > > Is this a bug ?
> > > If not, why ?
> > >
> > > The problem for me is that I use drupals behind proxies (they are in  
> > > a company LAN, using internal DNS which
> > > are not accessible from outside). When giving absolute pathes, the  
> > > site give me, through the proxy an internal
> > > DNS which does not work.
> > >
> > > -- 
> > > [ Drupal support list | http://lists.drupal.org/ ]
> > 
> 
> -- 
> [ Drupal support list | http://lists.drupal.org/ ]



More information about the support mailing list