我正在尝试上传数据库中的图片,但是当我检查它是否已上传时,该字段为空。我还想限制上传文件类型格式jpeg、png 和gif。请帮忙
HTML
<form enctype="multipart/form-data" action="subePic.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>
PHP
<?php
require('conecta.php');
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
$tmpName = $_FILES['image']['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$xSQL = "INSERT INTO FOTOS (PIC) VALUES(?)";
$stmt = $oConni->prepare($xSQL);
$stmt->bind_param('s', $data);
$stmt->execute() or die($oConni->error);
$stmt->close();
if(!$xSQL){
die("Database query failed: ". mysql_error());
}
print "Su foto fue subida con éxito";
}
else{
print "Error: no se subió ninguna imagen a la BD";
}
?>
我是一名优秀的程序员,十分优秀!