FTP question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Hulbert

    #1

    FTP question

    Ok Its getting late and i am getting tired. what stupid mistake am I making
    here:

    <?php
    $filepath = $_REQUEST['filepath']; // this is the path to say music/preview
    or /cd_covers
    $ftp_server = 'ftp.XXXXX.co.u k';
    $ftp_user_name = 'xxxxxxx';
    $ftp_user_pass = 'xxxxxxxx';
    $file = $_FILES['userfile']['name'];
    $remote_file = $filepath.$file ;
    // set up a connection or die
    $conn_id = ftp_connect($ft p_server) or die("Couldn't connect to
    $ftp_server");
    $login_result = ftp_login($conn _id, $ftp_user_name, $ftp_user_pass) or
    die("login failed"); // logs the user or sets an error message

    if(ftp_chdir($c onn_id, $filepath)){
    }else{
    echo "Directory doesnot exist";
    exit;
    }
    // upload a file\


    if (ftp_put($conn_ id, $remote_file, $file, FTP_BINARY)) {
    echo "successful ly uploaded $file\n";
    } else {
    echo "There was a problem while uploading $file\n";
    }

    ftp_close($conn _id);
    ?>


    straight out of the manual what gives?


    Cheers Richard
  • Cameron

    #2
    Re: FTP question

    Richard Hulbert wrote:[color=blue]
    > Ok Its getting late and i am getting tired. what stupid mistake am I
    > making here:
    >[/color]
    <code snip>

    The actual error message or what ever would be helpful.

    ~Cameron

    Comment

    • Pedro Graca

      #3
      Re: FTP question

      Richard Hulbert wrote:[color=blue]
      > Ok Its getting late and i am getting tired. what stupid mistake am I making
      > here:
      >
      ><?php
      > $filepath = $_REQUEST['filepath']; // this is the path to say music/preview
      > or /cd_covers
      > $ftp_server = 'ftp.XXXXX.co.u k';
      > $ftp_user_name = 'xxxxxxx';
      > $ftp_user_pass = 'xxxxxxxx';
      > $file = $_FILES['userfile']['name'];
      > $remote_file = $filepath.$file ;[/color]
      (snip)

      if I update a file named XXX, seems like $remote_file will have either
      music/previewXXX or /cd_coversXXX

      Are you sure that is what you want?


      What exact error do you get? At which instruction?

      This is like asking us to guess what is the license plate on your car
      just be telling us it's a FOOBAR model!
      --
      --= my mail box only accepts =--
      --= Content-Type: text/plain =--
      --= Size below 10001 bytes =--

      Comment

      • Richard Hulbert

        #4
        Re: FTP question

        On 2004-02-23 19:06:53 +0000, Pedro Graca <hexkid@hotpop. com> said:
        [color=blue]
        > Are you sure that is what you want?
        >
        >
        > What exact error do you get? At which instruction?
        >
        > This is like asking us to guess what is the license plate on your car
        > just be telling us it's a FOOBAR model!
        > -- --= my mail box only accepts =--
        > --= Content-Type: text/plain =--
        > --= Size below 10001 bytes =--
        >[/color]
        Firstly Thanks for answering.

        Ok Sorry let me step back a bit. firstly here is what i am trying to do:

        I am building a CMS that needs to upload two supporting files to
        directories on the public server. I want to do this from another site, at
        the moment I am doing this from localhost on my dev machine.

        I thought FTP option would be better in terms of preventing php actually
        writing files to the server.

        Ok so the Error - I don't get an error as such, i connect in, can navigate
        directories,etc it is the last call that is giving me a problem.

        if (ftp_put($conn_ id, $remote_file, $file, FTP_BINARY)) {
        echo "successful ly uploaded $file\n";
        } else {
        echo "There was a problem while uploading $file\n";
        }

        now $remote file is a string right? somthing like /music/previews/abc.mp3
        and $file is from $file = $_FILES['userfile']['name'];

        basically ftp_put fails and I Echo There was a problem...

        am i missunderstandi ng how to use the $_FILES object in this context?


        thanks Richard





        Comment

        • Richard Hulbert

          #5
          Re: FTP question

          SNIP

          aha I have was indeed missing how to reference the file object. so to make
          it all work really well.

          $upload = (ftp_put($conn_ id, $filepath . $_FILES['userfile']['name'],
          $_FILES['userfile']['tmp_name'], FTP_BINARY));

          the key being $_FILES['userfile']['tmp_name']

          i am now going to write one hundred times 'php references everything from
          the server !'

          thanks Richard


          Comment

          • Dan Tripp

            #6
            Re: FTP question

            > i am now going to write one hundred times 'php references everything[color=blue]
            > from the server !'[/color]

            Nah, just write a loop with a counter and that'll do it. ;)

            - Dan

            Comment

            Working...