SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow PHP - Problem with POST files

    Hi everybody,

    I have a server (lets call it S_1) running IIS and PHP over Windows 2008 and I'm trying to make an ftp from that server to a second server (lets call it S_2) through the users connected to de S_1 via http (website).

    The clients go to S_1 through a browser (where is the web application) and they charge a picture file that should be transfer from their computers to de S_2.

    The method used to send the file is POST, but the problem is that when I retrieve the PATH information of the file (using a client connection), It shows the file name but not the path. However, when I make the same test but openning the website from the same S_1, then it sends the file and the path complete.

    The input that I use to locate the file is:
    <input name="archivo" type="file" id="1"/>

    The code I'm using to retrieve the file information is:
    $_POST["archivo"] ## Using PHP

    I really appreciate all the help that you can give

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Uploaded files are accessed through $_FILES, not $_POST

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using your suggestion in the next code

    function ConectarFTP(){
    $ftp_server = 'xxx.xxx.xxx.xxx';
    $ftp_user_name = 'usrxx';
    $ftp_user_pass = 'pwdxx';
    $id_ftp=ftp_connect($ftp_server,21,20);
    $resultado_login=ftp_login($id_ftp,$ftp_user_name,$ftp_user_pass); ftp_pasv($id_ftp,true);
    return $id_ftp;
    }

    function UploadTheFile($File_local,$File_remote){
    $id_ftp=ConectarFTP();
    ftp_put($id_ftp,$File_remote,$File_local,FTP_BINARY);
    $_SESSION['pre_basename']=$_SESSION['basename'];
    }

    function ObtenerRuta(){
    $id_ftp=ConectarFTP();
    $Directorio=ftp_pwd($id_ftp);
    ftp_quit($id_ftp);
    return $Directorio;
    }

    if(isset($_FILES["File"])){
    $_SESSION['basename']=basename($_FILES["File"]);
    UploadTheFile($_FILES["File"],basename($_POST["File"]));
    unset($_POST["File"]);
    }

    But when I check on $_FILES["File"] I receive nothing which is different of $_POST["File"] where I receive the file name at least. In other hands the $_POST work perfect when I'm sending the file from the same server that receives it. How could thata be?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should look at the PHP manual's section on file uploads. $_FILES['File'] would be an array, the file name is just one of several keys. Also make sure the enctype on your form is correct for uploading a file.

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made a change, having your considerations. Let me show you:

    <?php
    $cid = ftp_connect("xxx.xxx.xxx.xxx");
    $resultado = ftp_login($cid, "log","pasw");
    if ((!$cid) || (!$resultado)) {
    echo "Connection failed"; die;
    } else {
    echo "Connected";
    }
    ftp_pasv ($cid, true) ;
    echo "<br> Passive mode<br />";

    ftp_chdir($cid, "E:\\Inetpub\\wwwroot\\enpartes\\enpartes\\images");

    $local = $_FILES["archivo"]["name"];
    $remoto = $_FILES["archivo"]["tmp_name"];
    $tama = $_FILES["archivo"]["size"];

    echo "<br />$local<br />";
    echo "$remoto<br />";
    echo "uploading file...<br />";

    $ruta = "here comes an http route".$local;

    if ($tama<=$_POST["MAX_FILE_SIZE"]){
    if (is_uploaded_file($remoto)){
    copy($remoto, $ruta);
    }
    else {
    echo "it could not upload de file " . $local;
    }
    } else {
    echo "Exceed the max size...<br />";
    }
    echo " Ruta: " . $ruta;


    //cerramos la conexión FTP
    ftp_close($cid);
    ?>


    But I obtain only "it could not upload de file". Do I have to make something extra in ftp_chdir? some other configuration?

    Regards,


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
  •