views:

91

answers:

2
<?php

    $con=mysql_connect("localhost","root","");
        if(!$con)
        {
        die('Could Not Connect:'.mysql_error());
        } 


    mysql_select_db("tcs",$con);


    $upload_to = "./uploadedfiles/";
    move_uploaded_file(
        $_FILES["filename"]["tmp_name"],
        $upload_to . "/" . $_FILES["file"]["name"]
    );

    $sql="insert into employee values ('$_POST[username]','$_FILES[filename][name]')";

    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }



    echo "Employee Uploaded File"."$_FILES[file][name]";  //showing uploaded file name 

    ?>

But there are three problems..

  1. $sql="insert into employee values('$_POST[username]','$_FILES[filename][name]')";

By '$_FILES[filename][name]' this command file name is not saving in database.

and if i try this $sql="insert into employee values('username....','$_FILES["filename"]["name"]')" then error is displaying like syntex error... Now tell me plz how to send file name also in database plz write or edit above code.and how to add username id with this file so that it can be downloaded in future.

  1. Now if i try the same file name from another loaction to store in database(uploaded folder) then file is still same(means only one copy after 2 time uploading of same file name but from differnt locations)..

  2. How to download file if user want to download it.How server will know that this file name belongs to this this user and plz tell me the code for this purpose...

A: 

Basically you store images in a folder but in the database, you store only the file names of uploaded pics. Here is how to upload the files.

Sarfraz
A: 

To store images in our DB, you've got to make the field BLOB instead of VARCHAR.

amindzx