Tuesday, November 15, 2011

PHP Upload Image code

if (isset($_POST['submit']))
 {
 // get form data, making sure it is valid
 $id = mysql_real_escape_string(htmlspecialchars($_POST['id']));


 
  
 $current_image=$_FILES['image']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg"))
{
?>
<script type="text/javascript">
alert("unknown extension");

</script>

<? }
$time = date("fYhis");
$new_image = $time . "." . $extension;
$destination="uploads/".$new_image;
$action =  move_uploaded_file($_FILES['image']['tmp_name'], $destination);


 $image=$new_image;
 // check to make sure both fields are entered
 if ($image == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 // if either field is blank, display the form again

 }
 else
 {
 // save the data to the database
 //echo $image;

mysql_query("UPDATE gallery SET  image='$image' WHERE id='$id'")
 or die(mysql_error());
 $msg='<font size="-1" color="#0000FF" >Successfully Updated Record</font>';
 // once saved, redirect back to the view page

 }
 }


 ?>

No comments:

Post a Comment

Thank you for your Comment....

Popular Posts