Lassie Posted August 15, 2007 Share Posted August 15, 2007 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/65050-script-displays-php-code/ Share on other sites More sharing options...
gurroa Posted August 15, 2007 Share Posted August 15, 2007 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.) Quote Link to comment https://forums.phpfreaks.com/topic/65050-script-displays-php-code/#findComment-324623 Share on other sites More sharing options...
Lassie Posted August 15, 2007 Author Share Posted August 15, 2007 hi Thanks PHP is working fine with other programs in the application and with other applications. The file has a .php ext. looking at view source the whole code is viewable but not with any other programs. I dont know where to go from here? Quote Link to comment https://forums.phpfreaks.com/topic/65050-script-displays-php-code/#findComment-324647 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 is it in the html_public folder ? double check its .php check server in running got a link ? Quote Link to comment https://forums.phpfreaks.com/topic/65050-script-displays-php-code/#findComment-324651 Share on other sites More sharing options...
gurroa Posted August 15, 2007 Share Posted August 15, 2007 Perhaps try copy/paste into new file and save again. I've copied your code to a local file and it was compiled correctly. Quote Link to comment https://forums.phpfreaks.com/topic/65050-script-displays-php-code/#findComment-324659 Share on other sites More sharing options...
Lassie Posted August 15, 2007 Author Share Posted August 15, 2007 Thanks both. i dont have a link its localhost. server is runing. I wil check the other things and get back. Quote Link to comment https://forums.phpfreaks.com/topic/65050-script-displays-php-code/#findComment-324695 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.