Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Link to display uploaded image(s)


  • Please log in to reply
No replies to this topic

#1 batowiise


    CC Newcomer

  • Just Joined
  • PipPip
  • 17 posts

Posted 11 January 2011 - 06:29 AM

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;



// 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;

if ($sizeOK && $typeOK){
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)){
// 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);
$result = "$file uploaded successfully";
else {
$result = "Error uploading $file. Please try again.";
case 3:
$result = "Error uploading $file. Please try again.";
$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.";

  • 0

Also tagged with one or more of these keywords: max_file_size

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download