SS Nath

SS Nath

  • NA
  • 1
  • 2.7k

How to replace the uploaded file in php edit page?

Jan 24 2013 3:58 AM
I used the following code to upload the pdf file.

<?ob_start();?>
<?php
session_start();
 ?>

 <?php
 if(array_key_exists('insert',$_POST))
 {  
            include("config.php");

            $frmt_code=$_POST[frmt_code];
            $frmt_des=$_POST[frmt_des];
            $version_no=$_POST[version_no];
            $version_date=$_POST[version_date]; 
            $Dept_Name=$_POST[Dept_Name]; 
            $pdf_file=$_POST[pdf_file]; 
            $sql="INSERT INTO format_master (frmt_code,frmt_des,version_no,version_date,Dept_Name,pdf_file)VALUES('$frmt_code','$frmt_des','$version_no','$version_date','$Dept_Name','".$_FILES['pdf_file']['name']."')";


  $path= "pdf/".$HTTP_POST_FILES['pdf_file']['name'];

  if($pdf_file !=none)
  {
  if(copy($HTTP_POST_FILES['pdf_file']['tmp_name'], $path))
  {

  }
  else
  {
  echo "Error";
  }
  }
  $result=mysql_query($sql) or die(mysql_error());
            if ($result)
            {
                header('Location:    http://localhost/EMP/frmtview.php');
                exit;
                }


  }
  ?>

  <html>
   <body>
   <form action="" method="post" enctype="multipart/form-data" >
   <table width="600" border="0" cellspacing="0" cellpadding="0">

  <tr>
  <td align="left" valign="middle"><label for="frmt_code">Format Code</label>
  </td>
  <td align="left" valign="middle"><label for="textfield"></label>
    <input name="frmt_code" type="text" id="frmt_code"/></td>
  </tr>

  <tr>
  <td align="left" valign="middle"><label for="frmt_des">Format Description</label>
  </td>
  <td align="left" valign="middle"><input name="frmt_des" type="text" id="frmt_des"/>    </td>
  </tr>

  <tr>
  <td align="left" valign="middle"><label for="version_no">Version Number</label>
  </td>
  <td align="left" valign="middle"><input name="version_no" type="text" id="version_no"/></td>
  </tr>

  <tr>
  <td align="left" valign="middle"><label for="version_date">Version Date</label>
  </td>
  <td align="left" valign="middle">:</td>
  <td align="left" valign="middle"><input name="version_date" type="text" id="datepicker" /></td>
  </tr>

  <tr>
  <td align="left" valign="middle">Deportment  Name</td>
  <td align="left" valign="middle">:</td>
  <td align="left" valign="middle"><select name='Dept_Name'>
      <option value="">--- Select ---</option>
        <?
           include("config.php");
            $select="hoshin";
            if (isset ($select)&&$select!=""){
            $select=$_POST ['Dept_Name'];
        }
        ?>
        <?
            $list=mysql_query("select * from dept_master order by Dept_Name asc");
        while($row_list=mysql_fetch_assoc($list)){
            ?>
                <option value="<? echo $row_list['Dept_Name']; ?>"<?     if($row_list['Dept_Name']==$select){ echo "selected"; } ?>>
                          <? echo $row_list['Dept_Name']; ?>           
                </option>
            <?
            }
            ?>
        </select></td>
   </tr>

  <tr>
  <td align="left" valign="middle">File Name</td>
  <td align="left" valign="middle">:</td>
  <td align="left" valign="middle"><input name="pdf_file" type="file"  id="pdf_file">   
  </td>
  </tr>


    <tr>
      <td width="60" align="left" valign="top">
        <input type="submit" name="insert" value="Submit"/></td>                 
    </tr>
    </table></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    <ob_flush();?>

Using this code file uploaded to the folder & the file name has stored in mysql database in row "pdf_file". I need to replace the file in edit page and want the path in view page. Is anybody can help me?