1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Upload Script!

Discussion in 'PHP' started by moxet, Oct 13, 2010.

  1. #1
    Hey All--
    I need a suggestion regarding PHP File Upload System--

    I have a user table having user's information, and an upload table having upload information, how i distinguish that these files belong to the specified user?

    I am in trouble from a bit days--

    Example:
    User Table
    > Jhon

    Jhon upload these file
    > document.pdf
    > cv.doc
    > exam.ppt

    how should i display these from table?
    Please Help
     
    moxet, Oct 13, 2010 IP
  2. SamT

    SamT Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need two table: Users table and Uploads table.

    You already have your Users table, I am guessing there is an Auto Increment field, for some sort of user_id?
    Now, create your upload table:
    • upload_id int(8) Auto Increment
    • user_id int(8)
    • upload_filename varchar(255)

    You can add other fields like filesize, file type, etc. For each upload, you will be entering a new row in that table, making sure user_id is the ID of the user doing the uploading. To fetch all uploads from a single user, just do a simple query:
    'SELECT * FROM uploads WHERE user_id = ' . (int) $user_id;
     
    SamT, Oct 13, 2010 IP
  3. moxet

    moxet Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Great--
    Done Sir
    Very Nice Explanation--

    Thank You Very Much
     
    moxet, Oct 14, 2010 IP
  4. sinha.sidhi

    sinha.sidhi Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if(!isset($_POST['upload']))
    {

    }
    else
    {
    $yourdomain = 'http://www.yourdomain.com/';
    //$uploaddir = 'upload/';
    $filename = $_FILES['file']['name'];
    $filetype=$_FILES['file']['type'];
    $filesize = $_FILES['file']['size'];
    $tmpname_file = $_FILES['file']['tmp_name'];
    $date_file = date(dmy);
    if(($filetype=="jpeg")|| ($filetype=="gif")|| ($filetype=="png") && ($filesize<20000) )

    {

    if(file_exists($filename))
    {
    echo "file is already exist";

    }
    else
    {
    move_uploaded_file($tmpname_file, "$filename");

    }
    }
    else
    {
    echo "invalid file";
    }
     
    sinha.sidhi, Aug 29, 2011 IP