php code for uploading a file


<?php
//----change acording to need--------------------
if ($_POST['submit']=="Update Products")
{
$query4 = "update sub_product set product_name ='".$_POST['desc']."' where id = '".$row['id']."' ";
mysql_query($query4) or die(mysql_error()."Couldn't update record information!");

$query2 = "select * from main_product where product_id='".$row['Product_id']."'";
$result2 = mysql_query($query2)or die(mysql_error()."Couldn't retrive record information!");
echo $row2 = mysql_fetch_array($result2);

if (file_exists("/images/sub_Product/". str_replace(" ","-",$row2['product_name'])."/" .$_FILES["image"]["name"]))
      {
      echo $_FILES["image"]["name"] . " already exists. ";
      }
    elseif($_FILES["image"]["name"])
           {
      move_uploaded_file($_FILES["image"]["tmp_name"],"images/sub_Product/". str_replace(" ","-",$row2['product_name'])."/" . $_FILES["image"]["name"]);
      $query4 = "update sub_product set image ='".$_FILES["image"]["name"]."' where id = '".$row['id']."' ";
mysql_query($query4) or die(mysql_error()."Couldn't update record information!");
      $_SESSION['msg'] = "One Product updated successfull";  
      }
   
$_SESSION['msg'] = "One Product updated successfully";
header("Location: sub_products.php");
exit;
}
?>

Comments

Popular Posta

How to enable .htaccess in wamp server

Web Scraping Amazon with PHP

Disable right click script and Google Instant Map Search