Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: PHP upload question

  1. #11
    Join Date
    Oct 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I agree with djr33...

    I think the point of the ftp functions is to get to a third party server.. Let's say for instance you want to upload a file to your web page, but you're really storing on another server (that has ftp access)...

  2. #12
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    How do you figure out 'tmp_name'?

  3. #13
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ok, I'm getting an error with this code - undefined index?

    PHP Code:
    $file $_REQUEST['file'];

    $basedir 'd:\webspace\ADMIN\alexjewell.com\WWW\amanda';

    $tmp_name $_FILES[$file]['tmp_name'];
    $new_name $_FILES[$file]['name'];

    move_uploaded_file($tmp_name $basedir.$new_name);

    echo 
    "<p>File uploaded successfully</p>"
    I think it's basically saying it can't find where the temp file's been uploaded. How do we find this out?

    ps - should I be using something along the lines of is_uploaded_file or $HTTP_POST_FILES?
    Last edited by alexjewell; 10-13-2006 at 01:00 AM.

  4. #14
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ok, I've worked around some code and done some things. The PHP errors are gone, but now my second die statement is showing up: "Couldn't upload file".

    I decided to echo the address of the new file, and it's really weird:

    I practiced with a file called hovers.js...this is what it echoed: d:\webspace\ADMIN\alexjewell.com\WWW\amanda\h
    It took the first letter and dropped the rest? I then used a file called js.php, and it ended up just like the h: amanda\j.

    PHP Code:
    $file $_REQUEST['file'] or die("<p>Could not retrieve file</p>");

    $basedir 'd:\webspace\ADMIN\alexjewell.com\WWW\amanda\\';

    $tmp_name $file['tmp_name'];
    $new_name $file['name'];

    echo 
    "<p>".$basedir.$new_name."</p>";

    move_uploaded_file($tmp_name $basedir.$new_name) or die("<p>Couldn't upload file</p>");

    echo 
    "<p>File uploaded successfully</p>"
    What's going on?!
    Last edited by alexjewell; 10-13-2006 at 12:14 PM.

  5. #15
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ok, the problem has been solved. I went with a different avenue altogether. But if anyone would like to point out the problems with the above script, that'd be cool.

  6. #16
    Join Date
    Oct 2006
    Location
    Delhi
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    First you can find out that it uses ASCII or binary.
    Then put it.

  7. #17
    Join Date
    Oct 2006
    Location
    Delhi
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    <?php

    // --------------------------------------------------------------------
    // THE TRIGGER
    // --------------------------------------------------------------------

    // set the various variables
    $ftproot = "/public_html/test/";
    $srcroot = "/home/kristy/scripts/";
    $srcrela = "iwm/";

    // connect to the destination FTP & enter appropriate directories both locally and remotely
    $ftpc = ftp_connect("ftp.mydomain.com");
    $ftpr = ftp_login($ftpc,"username","password");

    if ((!$ftpc) || (!$ftpr)) { echo "FTP connection not established!"; die(); }
    if (!chdir($srcroot)) { echo "Could not enter local source root directory."; die(); }
    if (!ftp_chdir($ftpc,$ftproot)) { echo "Could not enter FTP root directory."; die(); }

    // start ftp'ing over the directory recursively
    ftpRec ($srcrela);

    // close the FTP connection
    ftp_close($ftpc);

    // --------------------------------------------------------------------
    // THE ACTUAL FUNCTION
    // --------------------------------------------------------------------
    function ftpRec ($srcrela)
    {
    global $srcroot;
    global $ftproot;
    global $ftpc;
    global $ftpr;

    // enter the local directory to be recursed through
    chdir($srcroot.$srcrela);

    // check if the directory exists & change to it on the destination
    if (!ftp_chdir($ftpc,$ftproot.$srcrela))
    {
    // remote directory doesn't exist so create & enter it
    ftp_mkdir ($ftpc,$ftproot.$srcrela);
    ftp_chdir ($ftpc,$ftproot.$srcrela);
    }

    if ($handle = opendir("."))
    {
    while (false !== ($fil = readdir($handle)))
    {
    if ($fil != "." && $fil != "..")
    {
    // check if it's a file or directory
    if (!is_dir($fil))
    {
    // it's a file so upload it
    ftp_put($ftpc, $ftproot.$srcrela.$fil, $fil, FTP_BINARY);
    }
    else
    {
    // it's a directory so recurse through it
    if ($fil == "templates")
    {
    // I want the script to ignore any directories named "templates"
    // and therefore, not recurse through them and upload their contents
    }
    else
    {
    ftpRec ($srcrela.$fil."/");
    chdir ("../");
    }
    }
    }
    }
    closedir($handle);
    }
    }
    ?>

  8. #18
    Join Date
    Jun 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by alexjewell View Post
    Ok, the problem has been solved. I went with a different avenue altogether. But if anyone would like to point out the problems with the above script, that'd be cool.
    I'm curious how you solved this problem, I am working on trying to do the same thing right now, upload a file to a different server. I would cry if you could help me.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •