php - rename image during upload not working with Mysql set -


i have bellow code hoping change/rename image name on upload user id can avoid file overwrite , insert name database sadly after added rename code code not able upload image or update database out showing error if remove rename code working. can 1 me how solve or there better way can it?

<?php $user_id = htmlentities($_session['user']['id'], ent_quotes, 'utf-8'); $username = htmlentities($_session['user']['username'], ent_quotes, 'utf-8'); require("connection.php"); if(@$_post ['submit']) {     $file = $_files ['file'];     $name1 = $file ['name'];     $type = $file ['type'];     $size = $file ['size'];     $tmppath = $file ['tmp_name'];     if($type == 'jpeg' || $type == 'png' || $type == 'jpg') {         $name1 = $user_id.$type; // rename image         if($name1!="") {             if(move_uploaded_file ($tmppath, 'users/'.$name1)) {                 $sql=("insert users set photo='$name1' username='$username'");                 mysql_query ($sql) or die ('could not updated:'.mysql_error());                 echo ("profile picture updated");             }         }     }  } ?> 

you can try this, may ...

<?php $user_id = htmlentities($_session['user']['id'], ent_quotes, 'utf-8'); $username = htmlentities($_session['user']['username'], ent_quotes, 'utf-8'); require("connection.php"); if(@$_post ['submit']) { $file = $_files ['file']; $name1 = time().$file ['name']; // rename image $type = $file ['type']; $size = $file ['size']; $tmppath = $file ['tmp_name']; if($type == 'image/jpeg' || $type == 'image/png' || $type == 'image/jpg') {     if($name1!="") {         if(move_uploaded_file ($tmppath, 'users/'.$name1)) {             $sql=("insert users set photo='$name1' username='$username'");             mysql_query ($sql) or die ('could not updated:'.mysql_error());             echo ("profile picture updated");         }     } }  }} ?> 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -