Jump to content

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

See source of the page that is returned. I think the whole code is displayed. (part that you can't see is in tag and hidden)

Check wheter php is installed properly.

Check wheter your file has acceptable extension (.php, .php5 etc.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.