0
我有一个网站在用户上传自己的个人资料图片,我已经存储了PIC文件夹中和他们联系,反映在数据库 档案相片如何显示的是,在我有地方链接显示照片?显示用户上传使用PHP
上传照片
define ("MAX_SIZE","1000");
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")
&& ($extension != "gif")&& ($extension != "JPG") && ($extension != "JPEG")
&& ($extension != "PNG") && ($extension != "GIF"))
{
echo '<h3>Unknown extension!</h3>';
$errors=1;
}
else
{
$size=filesize($_FILES['image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
echo '<h4>You have exceeded the size limit!</h4>';
$errors=1;
}
$image_name=time().'.'.$extension;
$newname="photo/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h3>Copy unsuccessfull!</h3>';
$errors=1;
}
else echo '<h3>uploaded successfull!</h3>';
//mysql_query("insert into tutor (photo) values('".$newname."')");
$myphoto= ".$newname.";
}
代码插入代码
$mysqli = new mysqli("localhost", "***", "***", "***");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO `table` (`photo`) VALUES ( ?)"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
/* Prepared statement, stage 2: bind and execute */
if (!$stmt->bind_param('s',$myphoto)) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
我有用于检索图象$ RS码=的mysql_query( “选择从导师*”); \t如果($ RS) \t \t而($行= mysql_fetch_array($ RS)) \t \t { \t \t?> \t \t
问题已解决... thanx :) –