두 개의 테이블이 포함 된 'mysqlproject'라는 데이터베이스가 있습니다. 나는이 같은 데이터베이스에 마커 이름과 선언에 흥미 오전 테이블 중 하나 열이미지 URL을 MySQL 데이터베이스에 저장
CREATE TABLE IF NOT EXISTS `markers` (
`id` int(11) NOT NULL,
`TitleEvent` varchar(60) NOT NULL,
`Description` varchar(80) NOT NULL,
`lat` float(10,6) NOT NULL,
`lng` float(10,6) NOT NULL,
`type` varchar(255) NOT NULL,
`status` varchar(30) NOT NULL,
`EventUserName` varchar(60) NOT NULL,
`PhotosEvent` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=73 ;
하나는 거기에 내가 사진의 URL을 저장하려는 PhotosEvent
입니다. 그래서 난 자바 스크립트 파일을 통해 사진을 캡처하고 난 PHP 파일 "camera.php"
아약스 보내는 절차는에 아약스를 통해 보낸다 :
$.ajax({
type: "POST",
url: "camera.php",
data: {
imgBase64: dataURL
}
}).done(function(respond) {
// you will get back the temp file name
// or "Unable to save this image."
console.log(respond);
});
그래서 내가 방법 POST로 전송하고있는 이미지를 "camera.php"파일에 저장하십시오. PHP 파일에서 나는 그 이미지를 가져 와서 "EventImages"폴더의 "로컬 서버"에 먼저 저장합니다.
$connection = mysql_connect('localhost', 'root', '');
if (!$connection) //Success $Connection with server returns 1
{
die("Database Connection Failed" . mysql_error());
}
else
{
//Connection with server established
}
// Try Connection with mysql Database
$select_db = mysql_select_db('mysqlproject');
if (!$select_db) //Success $Connection with Database returns 1
{
die("Database Selection Failed" . mysql_error());
}
else
{
//Connection with Database established
}
: 좋아
은 데이터베이스와 연결 .. 그 작품 .. 하지만 난 분야는 활성 ID가있는 위치를 원료에서 "PhotosEvent"에서 데이터베이스에 이미지의 URL을 저장하려면 .PNG (작품) 및 데이터베이스에 URL을 저장 (작동하지 않는)이 시도로 폴더에 이미지를 저장 :if (isset($_POST["imgBase64"]) && !empty($_POST["imgBase64"])) {
define('UPLOAD_DIR', 'EventImages/');
// get the dataURL
$dataURL = $_POST["imgBase64"];
// the dataURL has a prefix (mimetype+datatype)
// that we don't want, so strip that prefix off
$parts = explode(',', $dataURL);
$data = $parts[1];
// Decode base64 data, resulting in an image
$data = base64_decode($data);
// create a temporary unique file name
$file = UPLOAD_DIR . uniqid() . '.png';
// write the file to the upload directory
$success = file_put_contents($file, $data);
// return the temp file name (success)
// or return an error message just to frustrate the user (kidding!)
print $success ? $file : 'Unable to save this image.';
$results = mysql_query("INSERT INTO markers (PhotosEvent) WHERE id ='".$_SESSION['id']."'VALUES('$dataURL')");
}
내 문제는 이미지 URL을 저장 - 경로를 데이터베이스에. 내가 어떻게 할 수 있니? 미리 감사드립니다.
행을 삽입하거나 기존 행을 업데이트하려고합니까? –
기존 업데이트 중 .. – monakons
UPDATE 마커 SET PhotosEvent = '$ dataUrl'WHERE id = $ _SESSION [ 'id'] –