mardi 5 mai 2015

Changing the path of the image inside the database

I found this coding on how to add image into the database and it is working perfectly fine. However, I would like to change the location of the image into a different folder/path.

So, when i add "../" to change the path it won't work.

Below is the coding that path has been changed.

<?php
include('dbconn.php');
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}
else{
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);

        move_uploaded_file($_FILES["image"]["tmp_name"],"../photo/" . $_FILES["image"]["name"]);

        $location="../photo/" . $_FILES["image"]["name"];
        $emp_id=$_POST['emp_id'];

        $save=mysql_query("INSERT INTO photo (location, emp_id) VALUES ('$location','$emp_id')");

        if( $save ) {
            echo "<script type='text/javascript'>
            alert('Successfully saved!');
             window.history.back();
            </script>";
        }
        else {
            echo "<script type='text/javascript'>alert('failed!')</script>";
        }



    exit();                 
}

This is the path I want it to be in my database. How I want it to be in the database

The path inside my database after I added ../ into the coding. enter image description here

Aucun commentaire:

Enregistrer un commentaire