...
 
Commits (2)
......@@ -5,4 +5,9 @@ CONST CONFIG = array(
'DB_USERNAME'=>'root',
'DB_PASSWORD'=>'',
'DB_DATABASE'=>'bookstore'
);
\ No newline at end of file
);
// configurations for ImageUploader
define("R_PATH", __DIR__);
define("F_PATH", R_PATH."/uploads");
define("F_SIZE", "4M");
\ No newline at end of file
<?php
require_once ("../autoload.php");
require_once ("../lib/imgupload.class.php");
function getUserProfile($id){
$conn = connect_to_mysql();
if ($conn !== NULL){
......@@ -24,7 +25,8 @@
}
}
function setUserProfile($id,$name, $address, $phone, $pp, $tmp_pp){
// function setUserProfile($id, $name, $address, $phone, $pp, $tmp_pp){
function setUserProfile($id, $name, $address, $phone, $tmp_image_name, $image_file){
$conn = connect_to_mysql();
if ($conn !== NULL){
if (($name !== NULL) and ($name !== "")){
......@@ -57,18 +59,20 @@
}
}
$upload_dir = "../uploads/";
if ($pp != NULL){
$upload_file_name = $upload_dir.$pp;
if (file_exists($upload_file_name) || move_uploaded_file($tmp_pp, $upload_dir.$pp)) {
$sql_query_picture = 'UPDATE user SET profile_picture = ? WHERE id = ?';
// $upload_dir = "../uploads/";
if ($tmp_image_name != NULL){
// $upload_file_name = $upload_dir.$pp;
// if (file_exists($upload_file_name) || move_uploaded_file($tmp_pp, $upload_dir.$pp)) {
// $sql_query_picture = 'UPDATE user SET profile_picture = ? WHERE id = ?';
if ($stmt = $conn->prepare($sql_query_picture)) {
$stmt->bind_param("si", $pp, $id);
$stmt->execute();
$stmt->close();
}
}
// if ($stmt = $conn->prepare($sql_query_picture)) {
// $stmt->bind_param("si", $pp, $id);
// $stmt->execute();
// $stmt->close();
// }
// }
$img = new ImageUpload();
$img->uploadImages($image_file, $id);
}
return 1;
} else{
......
......@@ -10,23 +10,20 @@
if (isset($_POST['submit'])){
// echo "MASUK SINI";
if(isset($_FILES["profile_picture"])){
$name = $_FILES["profile_picture"]["name"];
// $name = $_FILES["profile_picture"]["name"];
$tmp_name = $_FILES["profile_picture"]["tmp_name"];
} else{
$name = NULL;
// $name = NULL;
$tmp_name = NULL;
}
} else{
$name = NULL;
// $name = NULL;
$tmp_name = NULL;
}
// echo $update_name;
$update = setUserProfile($user_id, $update_name, $update_address, $update_phone, $name, $tmp_name);
// if ($update == 0){
// echo "<script type='text/javascript'>alert 'Update Failed';</script>";
// } else{
// echo "<script type='text/javascript'>alert 'Update Success';</script>";
// }
// $update = setUserProfile($user_id, $update_name, $update_address, $update_phone, $name, $tmp_name);
$update = setUserProfile($user_id, $update_name, $update_address, $update_phone, $tmp_name, $_FILES["profile_picture"]);
header('Location: ../profile');
exit;
?>
\ No newline at end of file
This diff is collapsed.