I had a file named start.php in my D:\Wamp folder.I need to upload the file and enter the full path ie D:\Wamp\start.php into my database.I did the code.But I am not getting the full file path in my database
the Code is as follows:

   <tr>
       <td width="71">Select a file <span style="color:#FF0000"></span></td>
       <td width="292"><input type="file" name="userfile" id="userfile"></td>
   </tr>

My php code is as follows:

$path = "uploads/";

$path = $path . basename( $_FILES['userfile']['name']); 

move_uploaded_file($_FILES['userfile']['tmp_name'], $path);

My database insertion code is as follows:

 $sql ="insert into invoice(filelocation) values('$path')";

Any help would be appreciated....

Recommended Answers

All 12 Replies

But i would like tio show the complete path in my database

$target_path = "uploader/";
$target_path = $target_path . basename($name=$_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path);    

  $sql ="insert into invoice(id,department,category,description,date,invoiceno,invoicedate,partyname,amount,filelocation) values('','$choice','$choice1','$desc','$date','$invoice','$invdate','$party','$amt','$name')";

My file is been uploaded but the filename is not inserted into my database.Any help would be appreciated.I want to insert the uploaded filename into my database.
i edited my code as follows

<tr>
    <td width="71">
        <div id="file-uploader-demo1">
          <div class="qq-uploader">
              <!--<div class="qq-upload-drop-area" style="display: none;">
                 <span>Drop files here to upload</span>
              </div>-->

              <div class="qq-upload-button" >
                Upload a file
                <input type="file" multiple="multiple" name="userfile" id="userfile">
              </div>
    </td>
           <ul class="qq-upload-list"></ul>
         </div>
       </div>
       <script type="text/javascript" src="fileuploader.js"></script>
       <script>
         function createUploader(){
          var uploader = new qq.FileUploader({
           element: document.getElementById('file-uploader-demo1'),
           action: 'do-nothing.htm',
           debug: true
          });
         }
         // in your app create uploader as soon as the DOM is ready
         // don't wait for the window to load
         window.onload = createUploader;
       </script>  
</tr>

this is my php code:

 $target = "./"; 
 $target = $target . basename( $_FILES['userfile']['name']); 
 $file=($_FILES['userfile']['name']); 
 $fileContents = file_get_contents($file);
 $sql ="insert into invoice(filelocation) values('$fileContents')";
Member Avatar for diafol

seems your html is badly formed as you have overlapping tags (td and divs).

i am also thinking that way.But i am little confused as how to align it.

this is my html code

<body>
<div align="center">
            <form action="addinvoice.php" method="POST" enctype="multipart/form-data">
                <table border="0" align="center">
                    <tr>
                        <td width="71">Department <span style="color:#FF0000"></span></td><td width="292"><select name="department">
<option value="software">software</option>
<option value="graphics">graphics</option>

</select></td>
<td width="53">Category <span style="color:#FF0000"></span></td><td width="271"><select name="category">
<option value="DMS">DMS</option>
<option value="ADMS">ADMS</option>

</select></td>
                    </tr>
                    <tr>
                        <td width="71" >Description <span style="color:#FF0000"></span></td>
                        <td width="292"><textarea name="description" cols="25" row="8"></textarea></td>
                        <td width="53" >Date <span style="color:#FF0000"></span></td>
                        <td width="271"><select name="date">
                                <option value="15-02-1980">15-02-1980</option><option value="18-02-1980">18-02-1980</option><option value="19-02-1980">19-02-1980</option><option value="20-02-1980">20-02-1980</option><option value="21-02-1980">21-02-1980</option>
                        </select></td>
                    </tr>
                    <tr>

                        <td width="71">Invoice no <span style="color:#FF0000"></span></td>
                        <td width="292"><select name="number">
                                <option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>
                        </select></td>
                        <td width="53" >Invoice Date <span style="color:#FF0000"></span></td>
                        <td width="271"><select name="invoicedate">
                                <option value="23-05-1980">23-05-1980</option><option value="28-05-1980">28-05-1980</option><option value="19-06-1980">19-06-1980</option><option value="17-07-1980">17-07-1980</option><option value="21-08-1980">21-08-1980</option>
                        </select></td>
                    </tr>
                      <tr>
                        <td width="71">Party name <span style="color:#FF0000"></span></td>
                        <td width="292"><select name="party">
                                <option value="Sivadaas">Sivadaas</option><option value="Karunakaran">Karunakaran</option><option value="Georgekutty">Georgekutty</option><option value="Sivasankaran">Sivasankaran</option><option value="Ajayan">Ajayan</option>
                        </select></td>
                        <td width="53" >Amount<span style="color:#FF0000"></span></td>
                        <td width="271"><input type="text" name="amount"></td>
                      </tr>
<!--                   <tr width="71">
                      <div id="file-uploader-demo1"><div class="qq-uploader">
                    <td width="292">     <div style="display: none;" class="qq-upload-drop-area"><span>Drop files here to upload</span></div>

<div style="position: relative; overflow: hidden; direction: ltr;" class="qq-upload-button">Upload a file
     <input type="file" name="userfile" id="userfile" multiple="multiple" >
    <input type="submit" value="Upload File" /></td>
    <input type="file" name="file" id="file">
</div><ul class="qq-upload-list"></ul></div></div>
                </tr>-->
                <tr>
                   <td width="71">
                   <div id="file-uploader-demo1">
<div class="qq-uploader">
<!--<div class="qq-upload-drop-area" style="display: none;">
<span>Drop files here to upload</span>
</div>-->

    <div class="qq-upload-button" width="71" >
Upload a file
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" multiple="multiple" name="file" id="file">
</div>
</td>
<!--<ul class="qq-upload-list"></ul>-->
</div>
</div>


                </tr>
                      <tr>
                        <td></td>
                        <td align="left"><input type="submit" name="submit"  value="submit"></td>
                    </tr>
                </table>                  
            </form>
        </div>
    </body>
Member Avatar for diafol

Be aware that 'multiple' doesn't work with IE9 and below - not sure about 10.

i checked without multiple.Still the code doesn't work.The files are uploaded but the filename is not showing when i use var_dump($_FILES)

when i used var_dump($_post),the flename is not shown and it is not reading the filename.That is why in database the filelocation is not shown.Anyone please help me in correcting my code

Your problem is this..

 $fileContents = file_get_contents($file);
 $sql ="insert into invoice(filelocation) values('$fileContents')";

file get_contents is for parsing text, html and coverting it to string. I really don't understand the reasons of using it, unless you want to collect webpages, text and store all of the parse contents in database. I thought all you need is the filename to be inserted in your database..

I need the filename path to be inserted.I am not getting filename in the database.What might be the reason?????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.