html - Images Uploading PHP -
i've been working on project relevantly easier took me it.
i made entire website between doctors , patients; i'm badly stuck in uploading , retrieving images!!
here code i've been building..
<?php session_start(); $un = "xxx"; $pw = "xxx"; $hn = "xxx"; $dbhandle = mysql_connect($hn, $un, $pw) or die("couldn't connect database"); mysql_set_charset('utf8'); $selected = mysql_select_db("dsnnet_login", $dbhandle); $myusername = $_session['snamed']; $target_dir = "uploaded/"; $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $sql = mysql_query("update doctable set photoname='$target_file' username= '$myusername'"); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); // check if image file actual image or fake image if(isset($_post["submit"])) { $check = getimagesize($_files["filetoupload"]["tmp_name"]); if($check !== false) { echo "file image - " . $check["mime"] . "."; $uploadok = 1; } else { echo "file not image."; $uploadok = 0; } } // check if file exists // check file size if ($_files["filetoupload"]["size"] > 500000) { echo "sorry, file large."; $uploadok = 0; } // allow file formats if($imagefiletype != "jpg" && $imagefiletype != "png" && $imagefiletype != "jpeg" && $imagefiletype != "gif" ) { echo "sorry, jpg, jpeg, png & gif files allowed."; $uploadok = 0; } // check if $uploadok set 0 error if ($uploadok == 0) { echo "sorry, file not uploaded."; // if ok, try upload file } else { if (move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file)) { echo "the file ". basename( $_files["filetoupload"]["name"]). " has been uploaded."; } else { echo "sorry, there error uploading file."; } } header("location: docp.php"); ?>
and "working page" follow:
<?php session_start(); $un = "xxx"; $pw = "xxx"; $hn = "xxx"; $dbhandle = mysql_connect($hn, $un, $pw) or die("couldn't connect database"); mysql_set_charset('utf8'); $selected = mysql_select_db("dsnnet_login", $dbhandle); $myusername = $_session['snamed']; $target_dir = "uploaded/"; $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $sql = mysql_query("update doctable set photoname='$target_file' username= '$myusername'"); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); // check if image file actual image or fake image if(isset($_post["submit"])) { $check = getimagesize($_files["filetoupload"]["tmp_name"]); if($check !== false) { echo "file image - " . $check["mime"] . "."; $uploadok = 1; } else { echo "file not image."; $uploadok = 0; } } // check if file exists // check file size if ($_files["filetoupload"]["size"] > 500000) { echo "sorry, file large."; $uploadok = 0; } // allow file formats if($imagefiletype != "jpg" && $imagefiletype != "png" && $imagefiletype != "jpeg" && $imagefiletype != "gif" ) { echo "sorry, jpg, jpeg, png & gif files allowed."; $uploadok = 0; } // check if $uploadok set 0 error if ($uploadok == 0) { echo "sorry, file not uploaded."; // if ok, try upload file } else { if (move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file)) { echo "the file ". basename( $_files["filetoupload"]["name"]). " has been uploaded."; } else { echo "sorry, there error uploading file."; } } header("location: docp.php"); ?>
can me figure out? i've been trying @ least 4 days now.. i'm not giving up.. i'm open learn..
thank guys:) cheers
check below
1.tag form have enctype="multipart/form-data"
2.if not localhost ,folder upload must set permittion 777
Comments
Post a Comment