<?php
session_start();
if($_SESSION['user']!=true)
{
    header('Location:login.php');
}
$error="";
?>

<?php
include("include/databaseq.php");

$title=$_POST['title'];
$date=$_POST['date'];
$description=$_POST['description'];


    function GetImageExtension($imagetype)
     {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
           default: return false;
       }
     }
if (!empty($_FILES["uploadedimage"]["name"])) {
    $file_name=$_FILES["uploadedimage"]["name"];
    $temp_name=$_FILES["uploadedimage"]["tmp_name"];
    $imgtype=$_FILES["uploadedimage"]["type"];
    $ext= GetImageExtension($imgtype);
    $imagename=date("d-m-Y")."-".time().$ext;
    $target_path = "/images/news/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {

    $query_upload="INSERT into recent_news (title,date,description,images_path,submission_date) VALUES

('$title','$date','$description','".$target_path."','".date("Y-m-d")."')";
    mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error()); 

?>
        <script>
  alert("News Updated");  


  window.location="recent_news.php";
    </script>    

    <?php    

}

else{
   exit("Error While uploading image on the server");
}
}
?>

Recommended Answers

All 3 Replies

My image upload function is working on local but not in Live.. This is the code
Please help me out

What exactly is wrong with it? Are there any error messages?

You can simply do a simple test.

Check for the upload directory permission

<?php

    echo substr(sprintf('%o', fileperms('/images/news/')), -4);

check for the file upload settings on your php.ini file can also be done this way

echo 'Maximum File Upload allowed: '. (ini_get('upload_max_filesize')) .'<br/>';
echo 'Post Max Size Setting: '. (ini_get('post_max_size')) .'<br/>';
echo 'Server Memory Setting:'. (ini_get('memory_limit')) .'<br/>';

You combine those codes above will pretty much give you the answers.

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.