Jump to content

[SOLVED] image doesn't upload


dennismonsewicz

Recommended Posts

I am trying to upload an image that is 4.5MB and my script is set to upload up to 3GB (JUST FOR TESTING) and for some reason the file doesn't upload. A link to the file appears but the actual upload does not happen.

 

here is my code

 

<?php

include "includes/header.php";
include "includes/sidebar.php";

?>

<div class="maincontent">

<?php
	$_SESSION['username'] = $_GET['username'];

		if($_POST['categories'])
		{		
				// ==============
				// Configuration
				// ==============
				$uploaddir = "imageuploads"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
				$allowed_ext = "pjpg, jpg"; // These are the allowed extensions of the files that are uploaded
				$max_size = "3221225472"; // 50000 is the same as 50kb
				$max_height = ""; // This is in pixels - Leave this field empty if you don't want to upload images
				$max_width = ""; // This is in pixels - Leave this field empty if you don't want to upload images

				$uploaded_by = $_SESSION['username'];
				$name = $_FILES['file']['name'];
				$filesize = $_FILES['file']['size'];
				$filetype = $_FILES['file']['type'];
				$url = "http://intranet.healthresources.net/hrstock/" . $uploaddir;
				$categories = $_POST['categories'];

				// Check Entension
				$extension = pathinfo($_FILES['file']['name']);
				$extension = $extension[extension];
				$allowed_paths = explode(", ", $allowed_ext);
				for($i = 0; $i < count($allowed_paths); $i++) {
				 if ($allowed_paths[$i] == "$extension") {
				 $ok = "1";
				 }
				}

				// Check File Size
				if ($ok == "1") {
				if($_FILES['file']['size'] > $max_size)
				{
				print "File size is too big!";
				exit;
				}

				// Check Height & Width
				if ($max_width && $max_height) {
				list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
				if($width > $max_width || $height > $max_height)
				{
				print "File height and/or width are too big!";
				exit;
				}
				}

				// The Upload Part
				if(is_uploaded_file($_FILES['file']['tmp_name']))
				{
				move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
				}
				echo "<div class='maincontentheader'>
						<h2>" . ucwords($_SESSION['username']) . ", thank you for your upload!</h2>
					</div>";
				echo "<p>Your file has been uploaded successfully! Yay!</p>";
				echo "<p> </p>";
				echo "<p><a href='upload.php?username=" . $_SESSION['username'] . "'>Upload another?</a></p>";
				include "includes/sql.php";
				$query = "insert into uploads (username, name, size, type, url, categories, number_of_downloads) " . "values ('$uploaded_by', '$name', '$filesize', '$filetype', '$url', '$categories', '0')";
				mysql_query($query) or die("ERROR: " . mysql_error());
				//on-th-fly thumbnail generator
						include "thumbtest.php";	
				} else {
				print "Incorrect file extension!";
}
				} else {
						echo '<div class="maincontentheader">
										<h2>' . ucwords($_SESSION['username']) . ', use the form below to upload an image!</h2>
									</div>

									<p>Make sure to add categories to this image.</p>
									<p> </p>
									<p>Adding categories allows for the image to show up during an image search!</p>
									<p> </p>
									<p>Example Categories: Cat, Dog, Ocean, Older Male, Female, etc...</p>
									<p> </p>
									<p style="font-size: 80%"><b>Note: if you have more than one category please make sure to separate them by a comma!</b></p>
									<p> </p>

									<!-- The data encoding type, enctype, MUST be specified as below -->
									<form enctype="multipart/form-data" action="upload.php?username=' . $_SESSION['username'] . '" method="POST" name="uploadfile">
										<!-- Name of input element determines name in $_FILES array -->
										<p>Image Categories: <input name="categories" type="text" /></p>
										<p> </p>
										<p>Upload this file: <input name="file" type="file" /></p>
										<p><input type="submit" value="Upload File" /></p>
									</form>';
								}				

						?>
                                                            
<div class="maincontentfooter"> </div>
                                
</div>


<?php include "includes/footer.php"; ?>

Link to comment
Share on other sites

you may want to change a couple others also

 

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 900     ; Maximum execution time of each script, in seconds
max_input_time = 900	; Maximum amount of time each script may spend parsing request data
memory_limit = 64M      ; Maximum amount of memory a script may consume (8MB)

 

along with

; Maximum allowed size for uploaded files.
upload_max_filesize = 10M

 

Ray

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.