ftp_put puts empty file =\

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

    #1

    ftp_put puts empty file =\

    Hi, im trying to upload a file from a client (windows) to an ftp
    server (linux), i deciede to use some of php`s functions to connect
    and authenticate etc.. i only wish to put a file on the server, so i
    used ftp_put() function, when i send the file via http, the file is
    created on the server, but it is empty, i checked the permissions and
    all are set correctly, i figured if it is empty it means it cant find
    the file im trying to upload, i read somewhere that it has problems
    with recognizing windows directory strings
    e.g(F:\this\dir ectory\file.txt ), i tryd minipulating the string but it
    still couldnt find the file, i figured that ftp_put sees the absolute
    path to the file from a windows box as the file name itself, so it
    maybe thinks F:\this\directo ry\file.txt is the actual file name, and
    dosent interpret the directory names, i really tryed every think i
    could think of, and nothing worked, here is the index.html and
    upload.php files that i used:

    index.html
    ---------------------------------
    <html>
    <body>
    <p>upload</p>
    <P>
    <form method=POST action="upload. php" enctype="multip art/form-data">
    Source File:<input type=file name=source_fil e size=20><BR>
    <input type=submit name=Submit value=Submit size=20 style="border: 1px
    solid #0000FF"></form>
    </body>
    </html>


    upload.php
    ----------------------------------
    <?php
    $server = "localhost" ;
    $con = ftp_connect($se rver);
    $user = "user";
    $pass = "password";
    //destantion file
    $destination_fi le = "file.txt";
    ftp_login ($con, $user, $pass);
    //change directory to files where the permissions are set to 0777
    ftp_chdir($con, "files");

    //this is where it goes wrong.
    if (!ftp_put($con, $destination_fi le, $source_file, FTP_BINARY)){
    echo "$source_fi le wasent uploaded";
    } else {
    echo "$source_fi le was uploaded";
    }
    //close connection
    ftp_close($con) ;
    ?>

    ---------------------------------------------

    let me add, that when i echo`d the $source_file i noticed it
    displayed a blank, is that because im using the POST method ?, and
    when i use the GET method i see the directory as F:\\files\\file .txt ,
    so i used echo stripslashes($s ource_file); , but it still didnt
    find the file, if someone can find a flaw in what im doing please
    tell, also is there another method of transfering files to an ftp
    server via http without using php ?


    thank you
  • Agelmar

    #2
    Re: ftp_put puts empty file =\

    Just another register_global s problem.

    balzano_1 wrote:[color=blue]
    > Hi, im trying to upload a file from a client (windows) to an ftp
    > server (linux), i deciede to use some of php`s functions to connect
    > and authenticate etc.. i only wish to put a file on the server, so i
    > used ftp_put() function, when i send the file via http, the file is
    > created on the server, but it is empty, i checked the permissions and
    > all are set correctly, i figured if it is empty it means it cant find
    > the file im trying to upload, i read somewhere that it has problems
    > with recognizing windows directory strings
    > e.g(F:\this\dir ectory\file.txt ), i tryd minipulating the string but it
    > still couldnt find the file, i figured that ftp_put sees the absolute
    > path to the file from a windows box as the file name itself, so it
    > maybe thinks F:\this\directo ry\file.txt is the actual file name, and
    > dosent interpret the directory names, i really tryed every think i
    > could think of, and nothing worked, here is the index.html and
    > upload.php files that i used:
    >
    > index.html
    > ---------------------------------
    > <html>
    > <body>
    > <p>upload</p>
    > <P>
    > <form method=POST action="upload. php" enctype="multip art/form-data">
    > Source File:<input type=file name=source_fil e size=20><BR>
    > <input type=submit name=Submit value=Submit size=20 style="border: 1px
    > solid #0000FF"></form>
    > </body>
    > </html>
    >
    >
    > upload.php
    > ----------------------------------
    > <?php
    > $server = "localhost" ;
    > $con = ftp_connect($se rver);
    > $user = "user";
    > $pass = "password";
    > //destantion file
    > $destination_fi le = "file.txt";
    > ftp_login ($con, $user, $pass);
    > //change directory to files where the permissions are set to 0777
    > ftp_chdir($con, "files");
    >
    > //this is where it goes wrong.
    > if (!ftp_put($con, $destination_fi le, $source_file, FTP_BINARY)){
    > echo "$source_fi le wasent uploaded";
    > } else {
    > echo "$source_fi le was uploaded";
    > }
    > //close connection
    > ftp_close($con) ;[color=green]
    >>[/color]
    >
    > ---------------------------------------------
    >
    > let me add, that when i echo`d the $source_file i noticed it
    > displayed a blank, is that because im using the POST method ?, and
    > when i use the GET method i see the directory as F:\\files\\file .txt ,
    > so i used echo stripslashes($s ource_file); , but it still didnt
    > find the file, if someone can find a flaw in what im doing please
    > tell, also is there another method of transfering files to an ftp
    > server via http without using php ?
    >
    >
    > thank you[/color]


    Comment

    Working...