0

How to find the web root (www, html_public, etc) of a hosting to upload files automatically via the PHP ftp_put() function ?

The purpose is to propose the installation of a PHP script via a form or the users could send their FTP login.

Then, with a function PHP would upload and install the script remotely on the server. My complete function works perfectly, however I was unable to determine the web directory of the server.

Thank you in advance for your help.

Kind regards

5
  • Is web-root A) /var/www/ or B) a more specific sub-folder for a single (sub-)domain /var/www/vhost1/?
    – feeela
    Jul 16, 2012 at 9:41
  • 1
    Root in shared hosting is usually from /, so just search for any of www, public_html etc, in that folder. (Things are different with FTP connections to non-shared hosting however - do you want to cope with that too?)
    – halfer
    Jul 16, 2012 at 9:41
  • 1
    The only sure way is to look at the web server configurations. Also, it would help if you specify what kind of server it is and what type of access do you have on it. Do you only have FTP access? Do you have shell access? Is it a linux server running Apache? Otherwise, this question is too vague to answer. Jul 16, 2012 at 9:42
  • 1
    The purpose is to propose the installation of a PHP script via a form or the users could send their FTP login. Then, with a function PHP would upload and install the script remotely on the server. My complete function works perfectly, however I was unable to determine the web directory of the server.
    – Sandra
    Jul 16, 2012 at 9:55
  • As halfer says, most shared services do not expose the true path, but in effect chroot to it, so that the document root (or its parent user account is /. However, this is provider-specific so their is not hard and fast rule.
    – TerryE
    Jul 16, 2012 at 10:00

2 Answers 2

3

Have you check $_SERVER ?

Try this,

echo $_SERVER["DOCUMENT_ROOT"];
1
  • The question mentions ftp_put which implies that PHP is running on the client system, not the server.
    – Quentin
    Jul 16, 2012 at 9:44
1

Not 100% sure what you are trying to do here, but by uploading a file in your webroot with this content:

echo dirname(__FILE__);

You could receive the full root path on your server.

4
  • 1
    The question mentions ftp_put which implies that PHP is running on the client system, not the server. Even if it was running on the server, the path to the current file might not even be under the web root.
    – Quentin
    Jul 16, 2012 at 9:44
  • I know not or upload it because I don't know in advance the web root hosting.
    – Sandra
    Jul 16, 2012 at 9:44
  • @Quentin : Of course, I did not see that when I posted. That makes it a bit harder, but you could try to upload this file to the server and access it? I don't have much experience with this function, and the few times I've worked with it, I've uploaded files to the current server. Jul 16, 2012 at 9:47
  • The only way to do it would be to poke around and see if common directories where the web root often appeared exist … which would be somewhat dangerous.
    – Quentin
    Jul 16, 2012 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.