php - rename profile picture on upload and insert into database -
can 1 me implement upload script, following code able upload images database therefore change/rename image being uploaded user id uploading image profile picture avoid file overwrite , strictly upload .jpg , .png file only
, advice may give appreciate.
<?php require("connection.php"); if(@$_post ['submit']) { $file = $_files ['file']; $name1 = $file ['name']; $type = $file ['type']; $size = $file ['size']; $tmppath = $file ['tmp_name']; if($name1!="") { if(move_uploaded_file ($tmppath, 'users/'.$name1)) { $query="insert profiles set photo='$name1'"; mysql_query ($query) or die ('could not updated:'.mysql_error()); echo "profile picture updated"; } } } ?>
<?php require("connection.php"); if(@$_post ['submit']) { $file = $_files ['file']; $type = $file ['type']; $name1 = $user_id.$type; $size = $file ['size']; $tmppath = $file ['tmp_name']; if($type != 'jpg' || $type != 'png') { echo "file type must jpg or png." }else{ if($name1!="") { if(move_uploaded_file ($tmppath, 'users/'.$name1)) { $query="insert profiles set photo='$name1'"; mysql_query ($query) or die ('could not updated:'.mysql_error()); echo "profile picture updated"; } } }//must jpg or png } } ?>
Comments
Post a Comment