Jump to content

script displays php code


Lassie

Recommended Posts

i have an upload program which displays the phpcode.

I can't find the error.can some one spot the obvious?Thanks.

the code is diplayed from here (italised) lines 29 to 59.

 

// check that file is within the permitted size
  if ($_FILES['image']['size'] >[i]0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
    $sizeOK = true;
}[/i]

The code is

<?php
  	require_once ('./includes/config.inc.php');
require_once ('ts_fns.php') ;

// Set the page title and include the HTML header.
	include('includes/title.inc.php');
	include ('./includes/header.html');
// session start
  	session_start();

  		// 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 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 file is within the permitted size
  if ($_FILES['image']['size'] >0 && $_FILES['image']['size'] <= MAX_FILE_SIZE) {
    $sizeOK = true;
}

  // check that file is of an permitted MIME type
  foreach ($permitted as $type) {
    if ($type == $_FILES['image']['type']) {
      $typeOK = true;
  break;
  }
}
  
  if ($sizeOK && $typeOK) {
    switch($_FILES['image']['error']) {
  case 0:
	include('./includes/create_thumb.inc.php');
    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.";
}
  }
?>	

	  <form action="" method="post" enctype="multipart/form-data" name="uploadImage" id="uploadImage"> 
	  <fieldset>
  		<legend>Upload images for your timeshare</legend>
    	<p>
	<label for="image">Upload image:<em class="required">(only jpg,gif,png.Max size 50Kb)</em></label>
	<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
        <input type="file" name="image" id="image" />
    	</p>
    	<p>
        <input type="submit" name="upload" id="upload" value="Upload" />
    	</p></fieldset>	
	</form>

  	
  	
  <?php	
  	include ('./includes/footer.html');
exit();
?>

Link to comment
https://forums.phpfreaks.com/topic/65050-script-displays-php-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.