Jump to content

Syntax error with upload script


andrew_biggart

Recommended Posts

Ok I have written this script to upload images and auto thumbnail them but i am getting the white screen i cannot spot the syntax error please help.

	<?php

	$images_location = "../Profile_pics/";
	$thumbs_location = "../Profile_thumbs/";
	$thumb_width = 50;
	$maximum_size = 5000000;
	$results = "Click browse to locate your profile picture!";

	require ("uploader.php");

		if ($_POST) {
			//checking for image
			if ($_FILES['image']['name'] == "") {
			$results = "Please select the image you want to upload!" ;
			}
			//start of upload
			else {
				$size = filesize($_FILES['image']['tmp_name']);
				$filename = stripslashes($_FILES['image']['name']);
				$extension = get_image_extension($filename);

				if($size >$maximum_size) {
				$results = "Your Image is to big, please selecta smaller image!";

				else
				// allow only certain extensions
				if (($extension != "jpg") &&
				    ($extension != "jpeg") &&
					($extension != "png") &&
					($extension != "gif")) {
						$results = "Invalid image extension, images can only be .jpg, .jpeg, .png or .gif!";
				}
				//generates random name
				else
					$image_random_name = random_name(15).".".$extension;
					$copy = @copy($_FILES['image']['tmp_name'], $images_location.$image_random_name);

					if (!$copy) {
						$results = "There was a problem uploading your image, please try again!";

					else {
						create_thumbnail($images_location.$image_random_name,$thumbs_location.$image_random_name, $thumb_width);
						$results = "Your profile picture has been uploaded!";
					}
				}
			}
		}
	?>

 

Link to comment
https://forums.phpfreaks.com/topic/193517-syntax-error-with-upload-script/
Share on other sites

Didn't look through all your code but noticed this:

 

if($size >$maximum_size) {
$results = "Your Image is to big, please selecta smaller image!";
else

Should be...

 

if($size >$maximum_size) {
$results = "Your Image is to big, please selecta smaller image!";
}
else

Also note, if you just use the statement else without an opening bracket, only the 1st line of code after the else is executed with the "else" conditional, everything after that 1st line is ALWAYS executed regardless of whether the if is true or false.

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.