4 Replies - 968 Views - Last Post: 04 March 2009 - 10:20 PM Rate Topic: -----

#1 gregwhitworth   User is offline

  • Tired.
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,613
  • Joined: 20-January 09

Images aren't submitted?

Post icon  Posted 04 March 2009 - 09:22 PM

Ok.

So I have a form that is submitting news information to a database, and you have an option to include an image, the one problem though is it seems that the image isn't even submitted. Because when I echo for the image information I get absolutely nothing. I have a similiar script working for a different function and it works fine - maybe a second pair of eyeballs will help.

PHP CODE:
	if(!isset($submit)) {
			print "You must submit the form before proceeding <a href=\"http://www.whitworthgallery.org\">Click here to return to Whitworth Gallery</a>";
			}
			
		else {
		
				// Checks to see if the form was submitted
				if(isset($_POST['submit'])) {
					$title = $_POST['title'];
					$message = $_POST['message'];

						
						// checks to see if an image was uploaded from the news form
						if(!isset($_POST['news'])) {
							echo "The image has not been uploaded.";
							exit();
							}

						
						if(isset($_POST['news'])){
							$target = "../images/news/";					
							$imageinfo = getimagesize($_FILES['news']['tmp_name']);
						
							echo $target;
							echo $imageinfo;
							exit();
							
								if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/jpg') {
									echo "Sorry, we only accept GIF and JPEG images\n";
									exit;					
								}
								
								if($imageinfo['mime'] == 'image/gif') {
									$ext = '.gif';
									}
									
								if($imageinfo['mime'] == 'image/jpeg') {
									$ext = '.jpeg';
									}
									
								if($imageinfo['mime'] == 'image/jpg') {
									$ext = '.jpg';
									}
							
							$ran = rand();
							$filename = $ran . $ext;
									
							$target_path = $target . $filename; 
							
					
							/* if(move_uploaded_file($_FILES['news']['tmp_name'], $target_path)) {
								$_SESSION['update'] = "Updated: Large image " . $filename . " was uploaded.";
								}
						}
						$filename = $ran . ".jpg";
						mysql_query("INSERT INTO News (img, title, message ) VALUES ('$filename', '$title','$message')");				
						header ("Location: http://www.whitworthgallery.org/admin/editNews.php");
					
				} else {
					echo "There was an error uploading the file, please try again!";
				}*/
			}
}}




The form:

<table cellspacing="0" cellpadding="0" id="admin">
				<tr>
					<td colspan="2">ALL FIELDS ARE REQUIRED!</td>
				</tr>
				<form action="insertNews.php" method="post" enctype="multipart/form-data">
				<tr>
					<td>
						Title: 
					</td>					
					<td>
						<input type="text" size="50" name="title"/>
					</td>
				</tr>
				
				<tr>
					<td>
						Message: 
					</td>					
					<td>
						<textarea cols="30" rows="5" name="message" /></textarea>
					</td>
				</tr>
				
				<tr>
					<td>
						Image: 
					</td>					
					<td>
						<input type="hidden" name="MAX_FILE_SIZE" value="1500000" /><input type="file" name="news" />
					</td>
				</tr>
				
				<tr>
					<td>
						<input name="submit" value="Submit" type="submit" />
					</td>
				</tr>				
				</form>
			</table>



ALSO, if someone has any easier way of appending the correct extension to the image, please help me on that too.

This post has been edited by gregwhitworth: 04 March 2009 - 09:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Images aren't submitted?

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5554
  • View blog
  • Posts: 14,560
  • Joined: 18-April 07

Re: Images aren't submitted?

Posted 04 March 2009 - 09:59 PM

You don't want to be checking for $_POST["news"], check $_FILES["news"] itself for a value. The file being submitted is going to be present in the $_FILES array if it is present at all. It will not be included in $_POST.

:)
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3839
  • View blog
  • Posts: 14,005
  • Joined: 08-August 08

Re: Images aren't submitted?

Posted 04 March 2009 - 10:04 PM

Are you saying that:
echo $imageinfo;
produces nothing?

Oops, I guess it is. Martyr2 spotted your problem.

This post has been edited by CTphpnwb: 04 March 2009 - 10:06 PM

Was This Post Helpful? 0
  • +
  • -

#4 gregwhitworth   User is offline

  • Tired.
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,613
  • Joined: 20-January 09

Re: Images aren't submitted?

Posted 04 March 2009 - 10:14 PM

Awesome thanks, but about the extensions. Now when it uploads the file it has an extension of '.jpg' but in the database it says '.jpeg' Thus the image doesn't work when I call it because the 2 values are different. Any solutions.

The code for the extension creation is here:

  if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/jpg') {
									echo "Sorry, we only accept GIF and JPEG images\n";
									exit;					
								}
							   
								if($imageinfo['mime'] == 'image/gif') {
									$ext = '.gif';
									}
								   
								if($imageinfo['mime'] == 'image/jpeg') {
									$ext = '.jpeg';
									}
								   
								if($imageinfo['mime'] == 'image/jpg') {
									$ext = '.jpg';
									}
						   
							$ran = rand();
							$filename = $ran . $ext;
								   
							$target_path = $target . $filename; 


Was This Post Helpful? 0
  • +
  • -

#5 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5554
  • View blog
  • Posts: 14,560
  • Joined: 18-April 07

Re: Images aren't submitted?

Posted 04 March 2009 - 10:20 PM

Try first to make it an if-elseif-else statement instead of a series of if statements. This testing should be one set of statements. You wouldn't want your jpg mime testing to overwrite your jpeg test if jpeg was true.

Try that first and see if that solves the problem. let us know. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1