Web Analytics Made Easy -
StatCounter ftp upload function to work on all servers - CodingForum

Announcement

Collapse
No announcement yet.

ftp upload function to work on all servers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ftp upload function to work on all servers

    Hi,

    I'm trying to write a packagable script that needs upload functionality (similar to a forum attachment).

    www.domain.com/script <- location of the script
    www.domain.com/script/uploads <- where I want uploads to go

    I have noticed some servers use these root paths

    /home/username/public_html/
    /mnt/sites/www.domain.com/
    etc

    How do I connect to the same directory on all servers considering that the document root is different on them all?
    Design Portfolio

  • #2
    I don't think you can , there is no standard way of getting this information via FTP , you can use ftp_site() or ftp_raw() to pass commands but results will differ from server to server , as you note public_html , www , domain.com , www , httpdocs are all quite common.

    Looks to me like you need your end-user to know and enter the document root in a config file somewhere.

    I dont know your setup , you could probably call a page on the server that returned $_SERVER['DOCUMENT_ROOT'] and parse that , but its bad JUJU for anyone to be able to get that info so easily.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

    Comment


    • #3
      How do forums do it then?

      Surely they haven't worked out EVERY server confiuration possible and put in error checks for them all.

      Is there a way to do the same through opening a socket or anything?
      Design Portfolio

      Comment


      • #4
        Almost all forums have a configuration file usually edited by the user during setup.

        one of the fields will be the document root or at least the forum installation directory , from this they work out relative or absolute paths as required.

        using FTP your problem will more likely be that the ftp root and the document root may not always be the same e.g /home/user/public_html/directory may exist , but /home/user/public_ftp/directory may not.

        whats wrong with uploading files using forms and <inpput type="file" ... & $_FILES etc ? I think that is the normal way to do such things .. and then a relative path should be fine.
        resistance is...

        MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

        Comment


        • #5
          How do you upload from $_FILES without using FTP, my upload script is this...

          PHP Code:
          function upload($file,$remote_file) { //$file = $_FILES['userfile'], $remote_file = new name
              
          $ftp_server='www.domain.com';
              
          $conn_id ftp_connect($ftp_server); 
              
              
          $user "username";
              
          $passwd "password";
              
          $login_result ftp_login($conn_id$user$passwd); 
              
              if ((!
          $conn_id) || (!$login_result)) { 
                  
          $error "FTP connection has failed!";
                  return 
          false;
              }
              
              
          ftp_chdir($conn_id"www");
              
          ftp_chdir($conn_id"images");

              if (
          ftp_put($conn_id$remote_file$fileFTP_BINARY)) {
                  
          ftp_close($conn_id);
                  return 
          true;
              } else {
                  
          ftp_close($conn_id);
                  return 
          false;    
              }

          Design Portfolio

          Comment


          • #6
            PHP Code:
            <?php

            $filepath 
            "uploads/";

             
            copy ($_FILES['objfile']['tmp_name'], $filepath.$_FILES['objfile']['name']) 
                or die (
            "Could not copy file");

            echo 
            "file uploaded";


            ?>
            http://www.hazelryan.co.uk

            Comment


            • #7
              Does that script require 777 access?
              If so, how do you do that without FTP.
              Design Portfolio

              Comment

              Working...
              X