Hi all,
Need help on displaying image that I have uploaded. The user uploads scan images into a specific user session folder.
The user submits some requests to an approver and the approver vets the details along side with a link display the uploaded images.
So far I have been able to upload the image file but my biggest problem is providing the link to display the uploaded images.
Your help is welcome.
The upload code is as follows;
<?php
session_start();
//require_once("../admin/db.php");
// define a constant for the maximum upload size
define('MAX_FILE_SIZE', 51200);
if (array_key_exists('upload', $_POST)){
// define constant for upload folder
define('UPLOAD_DIR', 'C:/upload_test/');
// replace any space in original filename with underscores
// at the same time, assign to a simpler variable
$file = str_replace(' ', '_', $_FILES['image']['name']);
// convert the maximum size to KB
$max = number_format(MAX_FILE_SIZE/1024, 1).'KB';
// create an array of permitted MIME types
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png','application/pdf');
// begin by assuming the file is unacceptable
$sizeOK = false;
$typeOK = false;
// check that file is within the permitted size
if($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE){
$sizeOK = true;
}
// check that the file is of a permitted MIME type
foreach ($permitted as $type) {
if($type == $_FILES['image']['type']){
$typeOK = true;
break;
}
}
if ($sizeOK && $typeOK){
switch($_FILES['image']['error']){
case 0:
// $username would normally come from a session variable
$username = $_SESSION['username'];;
// if the subfolder does not exist yet, create it
if (!is_dir(UPLOAD_DIR.$username)){
mkdir(UPLOAD_DIR.$username);
}
// make sure file of same name does not already exist
if (!file_exists(UPLOAD_DIR.$username.'/'.$file)){
// move the file to the upload folder and rename it
$success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$username.'/'.$file);
}
else {
// get the date and time
ini_set('date.timezone', 'Europe/London');
$now = date('Y-m-d-His');
$success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$username.'/'.$now.$file);
}
if($success){
$result = "$file uploaded successfully";
}
else {
$result = "Error uploading $file. Please try again.";
}
break;
case 3:
$result = "Error uploading $file. Please try again.";
default:
$result = "System error uploading $file. Contact webmaster.";
}
}
elseif ($_FILES['image']['error'] == 4) {
$result = 'No file selected';
}
else {
$result = "$file cannot be uploaded. Maximum size: $max. Acceptable file type: gif, jpg, png, pdf.";
}
}
?>
Regards