3
이미지를 업로드하고 mysql db에 경로를 저장하는 코드를 작성하는 방법은 무엇입니까? 시도했지만 아무도 작동하지 않습니다.이미지 코드를 업로드하고 mysql db에 경로를 저장하는 방법
이미지를 업로드하고 mysql db에 경로를 저장하는 코드를 작성하는 방법은 무엇입니까? 시도했지만 아무도 작동하지 않습니다.이미지 코드를 업로드하고 mysql db에 경로를 저장하는 방법
한 가지 방법은 이미지를 업로드하여 서버의 폴더에 저장하고 이름을 mysql 데이터베이스에 저장하는 것입니다. 여기에 예제 :
먼저 우리가 업로드 ::
//file.html
Upload your file to the database...
<form action="upload.php" method="post" enctype="multipart/form-data" name="uploadform">
<input type="hidden" name="MAX_FILE_SIZE" value="350000">
<input name="picture" type="file" id="picture" size="50">
<input name="upload" type="submit" id="upload" value="Upload Picture!">
</form>
그런 다음 우리가 만들
양식을 만들 것입니다 upload.php로<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> Upload Image </title>
<?php
// if something was posted, start the process...
if(isset($_POST['upload']))
{
// define the posted file into variables
$name = $_FILES['picture']['name'];
$tmp_name = $_FILES['picture']['tmp_name'];
$type = $_FILES['picture']['type'];
$size = $_FILES['picture']['size'];
// if your server has magic quotes turned off, add slashes manually
if(!get_magic_quotes_gpc()){
$name = addslashes($name);
}
// open up the file and extract the data/content from it
$extract = fopen($tmp_name, 'r');
$content = fread($extract, $size);
$content = addslashes($content);
fclose($extract);
// connect to the database
include "connect.php";
// the query that will add this to the database
$addfile = "INSERT INTO files (name, size, type, content) VALUES ('$name', '$size', '$type', '$content')";
mysql_query($addfile) or die(mysql_error());
if(!empty($_FILES))
{
$target = "upload/";
$target = $target . basename($_FILES['picture']['name']) ;
$ok=1;
$picture_size = $_FILES['picture']['size'];
$picture_type=$_FILES['picture']['type'];
//This is our size condition
if ($picture_size > 5000000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($picture_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['picture']['tmp_name'], $target))
{
echo "The file ". basename($_FILES['picture']['name']). " has been uploaded <br/>";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
}
mysql_close();
echo "Successfully uploaded your picture!";
}else{die("No uploaded file present");
}
?>
</head>
<body>
<div align="center">
<img src="upload/<?php echo $name; ?>"
<br />
<a href="form.html">upload more images</a>
</div>
</body>
</html>
//getpicture.php
** // 마지막으로 connect.php **
google -> php 파일 업로드 -> http://php.net/upload –