Can't upload my file properly

Hi,

i am having trouble trying to upload my .jpg file onto my server allong with it’s information about it e.g file description onto my db. The code bellow:


if(isset($_POST['action']) and $_POST['action'] == 'upload')
{ 
    $description = mysqli_real_escape_string($link, $_POST['description']);
    $category = mysqli_real_escape_string($link, $_POST['category']);
    $file = ($_FILES['photo']['name']);
    
    $target = './images/';
    $target .= basename($_FILES['photo']['name']);
    
 
    // Checkk if a file was actually uploaded
    if(!is_uploaded_file($_FILES['photo']['tmp_name']) )
    {
       echo  $error = 'Error, there was no file uploaded';
          print_r($_FILES['photo']['tmp_name']);
 
       // include 'error.html.php';
        exit();
    }
    
      if(file_exists($target))
      {
        $error = 'This file already exists on the server';
        echo ($target);
        include 'error.html.php';
        exit();
      }
      
      
      if(move_uploaded_file($_FILES['photo']['tmp_name'],$target))
      { 
          // Get information from the form
          $uploaddesc = $_POST['description'];
          $uploadcat = $_POST['category'];  
          $uploadname = $_FILES['photo']['name'];  
          
           
           //Prepare for user submitted for safe database insert
          $uploaddesc = mysqli_real_escape_string($link, $uploaddesc);
          $uploadcat = mysqli_real_escape_string($link, $uploadcat);
          $uploadname = mysqli_real_escape_string($link, $uploadname);
          
         include $_SERVER['DOCUMENT_ROOT'] . '/includes/shanghai_db.inc.php';
          $sql = "INSERT INTO  image_detail SET Filename = '$uploadname',
                              Category = '$uploadcat', Description = '$uploaddesc'";
          
          
          
          if(!mysqli_query($link, $sql) )
          {
            $error = 'Database error storing file information';
            include 'error.html.php';
            exit();
          }
          else
          {
            
            $output = 'The file and information has been stored successfully';      
            include 'success.html.php';
          }
           
      }
      else
      {
        die("Error moving file");
      }
      
      
}



 <form enctype="multipart/form-data" action=" " method="post">        
        <div>
        <label for="description"> Description: </label> <input type="text" name="description" id="description" /> <br >
        </div>
        
        <div>
            <label for="category"> Category </label>
            <select name="category" id="category">
                    <option value="Cheng_Huang_Temple">Cheng Huang Temple </option>
                    <option value="Shanghai_Zoo">Shanghai Zoo </option>
            </select> <br />
        </div>
        
        <div>
            <label for="uploadimg"> Upload Photo: </label>
         <input type="file" id="photo" name="photo"/> <br >
        </div>
        
        <div>
        <input type="hidden" name="action" value="upload" />
        <input type="submit" value="Upload" />
        </div>
    </form>



for some reason why i submit my file allong with it’s info, php seems to go nito my, $error = ‘Error, there was no file uploaded’; state and i don’t know why. I looked at the tmp_name to see i was writing it correctly, but it is correct.
Can somebody please tell me why it seems to go into my eeror state please.

Thx

fattyjules, I have WAMP SERVER so it’s on my local machine not on a shared host, yes i can change the file permissions on the ‘images’ folder. I’m running windows vista and i looked at the security permissions and noticed under Users(Vista-PC\Users) Full Control, Write, Modify and Special Permissions have not been checked.

PHPSycho, in my html form i do have
<form enctype=“multipart/form-data” action=" " method=“post”>

UPDATE:

UPDATE: I believe the way i was trying to display my images was slightly incorrect. After i enter the information for each image file and upload an image and submit, i would then go to my browser and manually type the following address: http://localhost/shanghai2010/homepage.html.php which would show nothing. BUT when i submit the form with the information and the file and add the hard coded img tag it would actaully display that image.

Now that it would display that image, i immediately changed the code to:



	<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
			

Then i started again by adding an image and it’s relavant information, hitting the submit button but this time it is now showing the description:

what is shown on browser:



Array ( [name] => IMG_0242.JPG [type] => image/pjpeg [tmp_name] => C:\\wamp\	mp\\php1C86.tmp [error] => 0 [size] => 4463338 ) 
The file and information has been stored successfully 

?> 
Array ( [photo] => Array ( [name] => IMG_0242.JPG [type] => image/pjpeg [tmp_name] => C:\\wamp\	mp\\php1C86.tmp [error] => 0 [size] => 4463338 ) ) '; ?>  Description: Dragon head statue 
 
'; ?>  Description: Pond 
 
'; ?>  Description: Crowded square 
 
'; ?>  Description: Water fountain 
 
'; ?>  Description: Market area 
 
'; ?>  Description: Get me out of here! 
 
'; ?>  Description: Snake 
 
'; ?>  Description: peacock  

When viewing the source:


<p>
			Array
(
    [photo] => Array
        (
            [name] => IMG_0242.JPG
            [type] => image/pjpeg
            [tmp_name] => C:\\wamp\	mp\\php1C86.tmp
            [error] => 0
            [size] => 4463338
        )

)
			
						<table>
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> Dragon head statue <br> </td>
			</tr>
			
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> Pond <br> </td>
			</tr>
			
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> Crowded square <br> </td>
			</tr>
			
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> Water fountain <br> </td>
			</tr>
			
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> Market area <br> </td>
			</tr>
			
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> Get me out of here! <br> </td>
			</tr>
			
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> Snake <br> </td>
			</tr>
			
						
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <b>Description:</b> peacock <br> </td>
			</tr>
			
						</table>


I added print_r($_FILES); to see what was in my fils array.

Updatd html code:


<p>
			<?php print_r($_FILES); ?>
			
			<?php if( isset($images) ): ?>
			<table>
			<?php foreach ($images as $image): ?>
			
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 
				 
			<td> <?php echo "<b>Description:</b> ".$image['Description'] . " <br>"; ?> </td>
			</tr>
			
			<?php endforeach; ?>
			</table>
			<?php endif ;?>
		</p>

my php code is unchanged. Since when i add the

 <td><? php echo '<img src="./images/'.$image['Filename'].'" >';  ?> </td> 

code i’m guessing there is something wrong with the way it’s written perhaps?? because if hard code every file image it would probably display all them but doing it this way it does not which i’m not sure why??

Sorry for any confusion if i have caused.

Debugging Tips:
1> Check for enctype=“multipart/form-data” in your html form
2> try print_r($_FILES)
3> try to locate the destination path

My guess would be that your PHP script doesn’t have permission to write files to that folder. Is it on a shared host? Can you change the file permissions on the images folder?