Ticket #560 (closed Bug: fixed)

Opened 7 years ago

Last modified 7 years ago

Try to autodetect virtual paths in the php connector

Reported by: alfonsoml Owned by: alfonsoml
Priority: Normal Milestone: FCKeditor 2.5 Beta
Component: Server : PHP Version: SVN (FCKeditor) - Retired
Keywords: Cc:

Description

realpath fails in PHP if the target directory doesn't exist, so it can't be used directly as server.mapPath in asp to get the proper physical path for a url, but I think that it should be possible to get up in the url path until it gets a match and then append the missing directories.

so it should go like this:
/john/userfiles/images/
-> it doesn't exit, then check
/john/userfiles/
-> it doesn't exit, then check
/john/
-> its physical path is /home/users/john/ , so we end up with a physical path of /home/users/john/userfiles/images/

The difference with the current method (if UserFilesAbsolutePath isn't specified) is that currently it would try to get the realPath of / that it can be /public/html and so it puts the files in /public/html/john/userfiles/images/

I just hope that it works fine

Change History

comment:1 Changed 7 years ago by fredck

I didn't understand it well.

Let's return to your example: /john/userfiles/images/.

Assuming that the virtual directory is "userfiles", which points to /public/files/, then the expected result is /public/files/images/, not /home/users/john/userfiles/images/.

I believe there is no real way to simulate Server.MapPath with PHP. It works with ASP, because it calls IIS to resolve the URL, which considers all virtual directories on it.

Probably I'm wrong...

comment:2 Changed 7 years ago by alfonsoml

I had a misunderstanding after reading comments about realPath and how it works, but it's in no way a substitute for the asp server.MapPath, but I have tested apache_lookup_uri and it seems to work fine (although I'm not sure if it's the best solution), so it's possible (we're talking now only about PHP on Apache, PHP users with IIS will have to do it the old way) to get this way the desired path.

This is what I've ended up doing

// Emulate the asp Server.mapPath function.
// given an url path return the physical directory that it corresponds to
function Server_MapPath( $path )
{
	// This function is available only for Apache
	if ( function_exists( 'apache_lookup_uri' ) )
	{
		$info = apache_lookup_uri( $path ) ;
		return $info->filename . $info->path_info ;
	}

	// This isn't correct but for the moment there's no other solution
	// If this script is under a virtual directory or symlink it will detect the problem and stop
	return GetRootPath() . $path ;
}

Checked in with [386] to be able to see all the code.

Now I can have the connector in a symlinked folder and the userfiles being also a symlink and it seems to work fine, it would be interesting to know if there are other options where the connector fails with Apache or if this can be done in another way.

comment:3 Changed 7 years ago by alfonsoml

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone set to FCKeditor 2.5

Fixed on trunk with [413]

Note: See TracTickets for help on using tickets.
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy