Opened 17 years ago

Closed 17 years ago

#560 closed Bug (fixed)

Try to autodetect virtual paths in the php connector

Reported by: Alfonso Martínez de Lizarrondo Owned by: Alfonso Martínez de Lizarrondo
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 (3)

comment:1 Changed 17 years ago by Frederico Caldeira Knabben

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 17 years ago by Alfonso Martínez de Lizarrondo

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 17 years ago by Alfonso Martínez de Lizarrondo

Milestone: FCKeditor 2.5
Resolution: fixed
Status: newclosed

Fixed on trunk with [413]

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy