PHP - Problem with POST files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
koanzen1940
Forum Newbie
Posts: 2
Joined: Wed Apr 29, 2009 12:02 pm

PHP - Problem with POST files

Post by koanzen1940 »

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
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: PHP - Problem with POST files

Post by it2051229 »

I think you're doing it wrong.. I mean I haven't used $_POST for uploading files but I use $_FILE....
there are a lot of tutorial on uploading files and you can google it.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP - Problem with POST files

Post by Benjamin »

Be sure to set the forms enctype:

Code: Select all

 
enctype="multipart/form-data"
 
And dig around in the manual:

http://us2.php.net/manual/en/features.f ... method.php
koanzen1940
Forum Newbie
Posts: 2
Joined: Wed Apr 29, 2009 12:02 pm

Re: PHP - Problem with POST files

Post by koanzen1940 »

I solved with the next code:

Code: Select all

 
<?php
    $cid = ftp_connect("xxx.xxx.xxx.xxx");
    $resultado = ftp_login($cid, "usr","pass");
    if ((!$cid) || (!$resultado)) {
        echo "Connection failed"; die;
    } else {
        echo "Connected.";
    }
    ftp_pasv ($cid, true) ;
    $local = $_FILES["archivo"]["name"];
    $remoto = $_FILES["archivo"]["tmp_name"];
    $tama = $_FILES["archivo"]["size"];
 
    $ruta = "E:/data/".$local;
 
 
    if ($tama<=$_POST["MAX_FILE_SIZE"]){
        if (is_uploaded_file($remoto)){
            copy($remoto, $ruta);
            echo(" Archivo arriba ");       
        }
        else {
            echo "Cant upload de file " . $local;
        }
    } else {
        echo "Exceeded the max size".<br />";
    }
    echo " Ruta: " . $ruta;
 
    ftp_close($cid);
?>
 
Last edited by Benjamin on Thu Apr 30, 2009 12:18 pm, edited 1 time in total.
Reason: Added code tags.
Post Reply