Thread: File uploading

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    58
    Rep Power
    14
    How do I upload a file to the same directory as my 'upload.php' file?

    Is it possible to do this without having knowning the hole filesystem tree.

    I've tried alot of things but don't get it to work
  2. #2
  3. No Profile Picture
    raghuram
    Guest
    Devshed Newbie (0 - 499 posts)
    Use the File Data Type to do this.

    <html>
    <body>
    <form enctype="multipart/form-data" method="post"
    action="<?php echo $PHP_SELF ?>">
    <input type="File" name="blah" size="25"><br>
    <input type="submit" name="submit" value="Upload">
    </form>
    <?php
    if ($submit) {
    exec("cp $blah complete path of your folder/$filename");
    //syntax for cp - cp Uploading File, Path where the file to be Uploaded.


    Enjoy

    Raghu.
    }
    ?>
    </body>
    </html>

  4. #3
  5. No Profile Picture
    raghuram
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by raghuram:
    Use the File Data Type to do this.

    <html>
    <body>
    <form enctype="multipart/form-data" method="post"
    action="<?php echo $PHP_SELF ?>">
    <input type="File" name="blah" size="25"><br>
    <input type="submit" name="submit" value="Upload">
    </form>
    <?php
    if ($submit) {
    exec("cp $blah complete path of your folder/$filename");
    //syntax for cp - cp Uploading File, Path where the file to be Uploaded.
    }
    ?>
    </body>
    </html>
    [/quote]


    Enjoy

    Raghu.
  6. #4
  7. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2000
    Location
    Enschede, The Netherlands
    Posts
    1,527
    Rep Power
    15
    Hi Raghu,

    I tried your code but somehow it didn't work with me. Maybe I didn't get the path-thing right, but I changed the code somewhat and now I can upload a file into a directory 'files', which is located in the same directory as my upload-script. So far so good!

    The problem is though I don't know how I can give the uploaded file the same name as the original. $blah is always C:WindowsTempPhp2 with me, so with my current script I get a file called php2. Is there a way to get this right?

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <html>
    <body>

    <form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF ?>">
    <input type="File" name="blah" size="25"><br>
    <input type="submit" name="submit" value="Upload">
    </form>

    <?php
    if ($submit) {
    $dir = "files";
    $filename = basename($blah);
    if (!copy($blah, $dir.$filename)) {
    print( "Oops! Something went wrong!");
    }
    }
    ?>

    </body>
    </html>
    [/code]

    Mirax

Similar Threads

  1. Pointer problems opening file *formatted*
    By LAKI in forum C Programming
    Replies: 4
    Last Post: February 11th, 2004, 06:06 AM
  2. Uploading multiple images using paths all in same .txt file?
    By MarlboroMan in forum Perl Programming
    Replies: 3
    Last Post: February 3rd, 2004, 05:34 PM
  3. .SQL file :: Uploading values
    By RuFFy in forum MySQL Help
    Replies: 1
    Last Post: January 28th, 2004, 08:26 AM
  4. Uploading file thru PHP Script ..
    By Rubal in forum IIS
    Replies: 2
    Last Post: January 28th, 2004, 02:17 AM
  5. Uploading a folder to an FTP file server
    By lildi in forum FTP Help
    Replies: 0
    Last Post: January 14th, 2004, 12:08 AM

IMN logo majestic logo threadwatch logo seochat tools logo