Commit cba22584 by sopham

image location to database

parent c6625a80
Showing with 9 additions and 18 deletions
...@@ -15,23 +15,6 @@ function myFunction() { ...@@ -15,23 +15,6 @@ function myFunction() {
document.getElementById("myBar").style.width = scrolled + "%"; document.getElementById("myBar").style.width = scrolled + "%";
} }
//display image
/*
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imagePreview').css('background-image', 'url('+e.target.result +')');
$('#imagePreview').hide();
$('#imagePreview').fadeIn(650);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imageUpload").change(function() {
readURL(this);
});
*/
//display input from database //display input from database
$(document).ready(function() { $(document).ready(function() {
$.ajax({ $.ajax({
...@@ -70,7 +53,7 @@ $(document).ready(function() { ...@@ -70,7 +53,7 @@ $(document).ready(function() {
var files = $('#imageUpload')[0].files[0]; var files = $('#imageUpload')[0].files[0];
fd.append('file',files); fd.append('file',files);
$.ajax({ $.ajax({
url: 'test.php', url: 'upload.php',
type: 'POST', type: 'POST',
data: fd, data: fd,
contentType: false, contentType: false,
......
<?php <?php
session_start(); session_start();
include_once 'dbconnection.php';
if(is_uploaded_file($_FILES['file']['tmp_name'])) { if(is_uploaded_file($_FILES['file']['tmp_name'])) {
$sourcePath = $_FILES['file']['tmp_name']; $sourcePath = $_FILES['file']['tmp_name'];
$targetPath = "upload/".basename($_SESSION['name'].'.'.end((explode(".", $_FILES['file']['name'])))); $targetPath = "upload/".basename($_SESSION['name'].'.'.end((explode(".", $_FILES['file']['name']))));
if(move_uploaded_file($sourcePath, $targetPath)) { if(move_uploaded_file($sourcePath, $targetPath)) {
$_SESSION['avatar'] = $targetPath; $_SESSION['avatar'] = $targetPath;
$query = "UPDATE users SET image=? WHERE username=?";
$query = $link->prepare($query);
$query->bind_param('ss', $targetPath,$_SESSION['name']);
$query->execute();
$query->close();
$link->close();
//echo $_SESSION['name'];
echo $targetPath; echo $targetPath;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment