create directory for upload file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • printline
    New Member
    • Jul 2006
    • 89

    create directory for upload file

    Hello all

    I have a php script that uploads a file from a form into a directory. The directory is automatically created through the script.

    But the upload file is not put in to the directory, but outside....

    Can anyone tell what i am doing wrong....?? And perhaps tell me what to do to put the file into the created directory...?

    Here is my code:

    [PHP]<?php

    // Your file name you are uploading
    $file_name = $HTTP_POST_FILE S['ufile']['name'];

    // random 4 digit to add to our file name
    // some people use date and time in stead of random digit
    $random_digit=r and(0000,99999) ;

    mkdir("D:\\Webs \\printline-webshop.eu\\htt pdocs\\searchpr o\\data\\".$ran dom_digit) or die ("Could not make directory");

    //combine random digit to you file name to create new file name
    //use dot (.) to combile these two variables

    $new_file_name= $random_digit.$ file_name;

    //set where you want to store files
    //in this example we keep file in folder upload
    //$new_file_name = new upload file name
    //for example upload file name cartoon.gif . $path will be upload/cartoon.gif
    $path= "D:\\Webs\\prin tline-webshop.eu\\htt pdocs\\searchpr o\\data\\".$new _file_name;
    if($ufile !=none)
    {
    if(copy($HTTP_P OST_FILES['ufile']['tmp_name'], $path))
    {


    //$new_file_name = new file name
    //$HTTP_POST_FILE S['ufile']['size'] = file size
    //$HTTP_POST_FILE S['ufile']['type'] = type of file

    }
    else
    {
    echo "Error";
    }
    }
    ?>[/PHP]

    Any help would gladly be appreciated...
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    First of all, the $HTTP_POST_FILE S array is old and shouldn't be used.
    Use the $_FILES super-global instead.

    The reason why your file isn't put into the folder is because you are not putting it into the folder. (obviously).

    What you are actually doing is:
    You create a random number.
    Then you create a new folder using that number (bad idea btw).
    Finally, you add that number to the file name and save it, rather than adding the file into the new folder.

    Take a look at the examples in the manual.
    You could easily modify one of them into what you need.

    Comment

    Working...