How do i do it so the image updates to database?

Status
Not open for further replies.

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
I want the image name + the extension (png, jpg, jpeg, gif) to update into the database into 'usersystem' > profile_picture

Code:
<?php
include 'core/init.php';
protect_page ();
$id = $_SESSION['id'];
?>
<?php
if (logged_in() === true) {
    $session_user_id = $_SESSION['id'];
    $user_data = user_data($session_user_id, 'profile_picture', 'first_name', 'last_name', 'status', 'location', 'education', 'home_town');
}
$data = array();
?>
<?php
define ('MAX_FILE_SIZE', 15000 * 50);
if (array_key_exists('upload', $_POST)) {
  define('UPLOAD_DIR', "avatars/".$id."/");
  $file = str_replace(' ', '_', $_FILES['image']['name']);
  $permitted = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png');
  if (in_array($_FILES['image']['type'], $permitted)
      && $_FILES['image']['size'] > 0
      && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
    switch($_FILES['image']['error']) {
      case 0:
        if (!file_exists(UPLOAD_DIR . $file)) {
          $success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR . $file);
        } else {
          $result = 'A file of the same name already exists.';
        }
        if ($success) {
          $result = "$file uploaded successfully.";
        } else {
          $result = "Error uploading $file. Please try again.";
        }
        break;
      case 3:
      case 6:
      case 7:
      case 8:
        $result = "Error uploading $file. Please try again.";
        break;
      case 4:
        $result = "You didn't select a file to be uploaded.";
    }
  } else {
    $result = "$file is either too big or not an image.";
  }
}
?>
 
 
<form action="" method="post" enctype="multipart/form-data"
name="uploadImage" id="uploadImage">
<p>
  <input type="hidden" name="MAX_FILE_SIZE"
    value="<?php echo MAX_FILE_SIZE; ?>" />
  <label for="image">Upload image:</label>
  <input type="file" name="image" id="image" />
</p>
<p>
  <input type="submit" name="upload" id="upload"
value="Upload" />
</p>
</form>
<?php
// if the form has been submitted, display result
if (isset($result)) {
  echo "<p><strong><img src='avatars/$id/$file'</strong></p>";
}
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top