updating image in upload folder and image path in mysql
I am trying to update images in my upload folder and mysql database the
file uploads giving the file name 0.jpg instead of the normal persons id
13.jpg and does not update in mysql database, here is my snippet below
what am i doing wrong?
$pic = mysql_real_escape_string(htmlspecialchars($_FILES['photo']['name']));
//This gets all the other information from the form
$pic=($_FILES['photo']['name']);
$file = $_FILES['photo']['name']; // Get the name of the file (including
file extension). $ext = substr($file, strpos($file,'.'), strlen($file)-1);
if(!in_array($ext,$allowed_filetypes))//check if file type is allowed
die('The file extension you attempted to upload is not allowed.'); //not
allowed if(filesize($_FILES['photo']['tmp_name']) > $max_filesize) //check
that filesize is less than 50MB die ('The file you attempted to upload is
too large, compress it below 50MB.');
// Connects to your Database mysql_connect("localhost", "root", "") or
die(mysql_error()) ; mysql_select_db("office") or die(mysql_error()) ;
//Writes the information to the
$target = "images/" .mysql_insert_id() . $ext;
$staff_id = mysql_insert_id(); $new_file_name = mysql_insert_id() . $ext;
//I removed ,photo='$target' to display only id as picture name
mysql_query("UPDATE development SET photo='$new_file_name' WHERE
staff_id=$staff_id");
//Writes the file to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
//Tells you if its all ok echo "The file ". basename(
$_FILES['photo']['name']). " has been uploaded, and your information has
been added to the directory"; `} else {
//Gives and error if its not echo "Sorry, there was a problem uploading
your file."; } ?>
No comments:
Post a Comment