Unidentified
Living the Developer Life...
- Jun 19, 2012
- 144
- 20
I would like to know how to change this so on upload it changes the files name please
PHP:
<?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', 1024 * 50);
if (array_key_exists('upload', $_POST)) {
define('UPLOAD_DIR', "avatars/".$id."/");
$file = str_replace(' ', '_', $_FILES['image']['name']);
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg', '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.";
}
}
?>