SitePoint Sponsor

User Tag List

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

    Files not uploaded in the directory that i want

    Dear all,
    below is the code i used to upload the file using ftp.
    Every thing is working. But i have problem that i do not get the files uploaded in the directory that i want. I have provided the directory name images in the following code which is inside www folder online. I am unable to solve this problem. Please help me.

    Hoping response from helpers.

    My code is:

    <?php
    if(!empty($_POST['uploadfile'])){
    $filepathname = $_POST['uploadfile'];
    $filename = basename($filepathname);
    $uid = 'xxxxxxxx';
    $pwd = 'xxxxx';
    $host = 'www.sitename.com';
    $ftp = ftp_connect($host) or die("Couldn't connect to $host");
    ftp_login($ftp,$uid,$pwd) or die("Couldn't log in to $host");
    ftp_chdir($ftp,"images");
    if(ftp_put($ftp,$filename,$filepathname,FTP_BINARY)){
    ftp_close($ftp);

    }
    else
    {
    die("<br>Could not transfer $filename to $host<br>");
    }
    }
    else
    {
    ?>
    <html>
    <head>
    <title>Upload Files</title>
    </head>
    <body>
    <form name="frmUpload" method="POST" action="<?php echo $_SERVER['PHP_SELF']?>" >
    <input type="file" name="uploadfile">
    <br>
    <input type="Submit" value="Submit">
    </form>
    </body>
    </html>
    <?
    }
    ?>

  2. #2
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you using $_POST for files? PHP has a built-in superglobal for handling files $_FILES. Try replacing images with /images.

  3. #3
    SitePoint Enthusiast lkagan's Avatar
    Join Date
    Sep 2007
    Location
    Boca Raton, Florida
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must be frustrated at this point because there are quite a few things wrong with the above code. The php.net site has exact details on handling file uploads. http://php.net/file_upload
    Larry Kagan
    Lead Web Application Developer
    Superiocity, Inc.


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
  •