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

Link to comment
Share on other sites

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.