move_uploaded_file and permissions

I’ve got an image upload script working and the folder permissions are good. I’m able to browse and upload a file to my server – the folder has 777 on it. But when I try to download that image from the server – (or I look at the permissions they are 600) I’m unable to download.

Should the images that are uploaded ‘take on’ the same permissions as the folder they’re being moved to? Can I set the permissions of the file when I upload it?

here’s what i’m working with:


if (array_key_exists('upload', $_POST)) {

// IMAGE UPLOADING STARTS HERE
  // replace any spaces 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');
  // begin by assuming the file is unacceptable
  $sizeOK = false;
  $typeOK = false;
  
  // check that the file size is within the permitted size
  if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
    $sizeOK = true;
   }
   
  // check that 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:
	    // make sure file of same name does not already exist
	   if (!file_exists(UPLOAD_DIR.$file)) {
	    // move the file to the upload folder and rename it
        $success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$file);
       }
	  else {
	  $success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.time().$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 types: gif, jpg, png.";
	}
  exit;
  }
?>

Any advice would be much appreciated!