Jump to content

[SOLVED] upload image problem


nadman123

Recommended Posts

here is my code:

 

<html>
<head>
<title>Add new Property</title>
    <link rel="stylesheet" href="stylesheet.css"
                           type = "text/css" />
</head>

<body>
<h3>Add new Property</h3>

<?php 


      if (empty($_POST["street"]) && !isset($_FILES["image"]["tmp_name"]))
      {
?>
      <form method="post" action="addProperty.php"> 
            <p>Please enter Property details below</p>
       <table>
       <tr>
       <th>Street Address</th>
       <td><input type="text" size="100" name="street"></td>
       </tr>
       <tr>
       <th>Suburb</th>
       <td><input type="text" size="20" name="suburb"></td>
       </tr>
       <tr>
       <th>State</th>
       <td><input type="text" size="1" name="state"></td>
       </tr>
       <tr>
       <th>Post Code</th>
       <td><input type="text" size="4" name="postcode"></td>
       </tr>
       <tr>
       <th>Price</th>
       <td><input type="text" size="7" name="price"></td>
       </tr>
       <tr>
       <th>Image</th>
       <td><input type="file" size="20" name="image"></td>
       </tr>
       <tr>
       <th>Type of property</th>
       <td><input type="text" size="1" name="type"></td>
       </tr>
       </table>
       <p />
       <input type="submit" value="Add  details" onClick="window.location='property.php'"/>
       <input type="reset" value="Clear Details"/>
       </form>
      
      
    
    
       
<?php 
       }
       else
       {
       
        include("connection.php");
        $conn = oci_connect($UName,$PWord,$DB)
        or die("Couldn't logon.");
        $query="INSERT INTO PROPERTY (PROPERTY_ID, PROPERTY_STREET, PROPERTY_SUBURB,
                PROPERTY_STATE, PROPERTY_POSTCODE,PROPERTY_PRICE, PROPERTY_IMAGE, PROPERTY_TYPE) VALUES
                (prop_id_seq.nextval,'".$_POST["street"]."','".$_POST["suburb"]."',
                '".$_POST["state"]."','".$_POST["postcode"]."','".$_POST["price"]."','".$_POST["image"]."',
                '".$_POST["type"]."')";
        $stmt = oci_parse($conn,$query);
        oci_execute($stmt); 
       
        ?>
        <?php
        oci_free_statement($stmt);
        oci_close($conn);
  ?>    
    
<?php 
$upfile = "uploads/".$_FILES["image"]["name"];
if(!move_uploaded_file($_FILES["image"]
      ["tmp_name"],$upfile))
    {
      echo "ERROR: Could Not Move File into Directory";
    }
    else
    {

?>              
   <p>New Property Addition was Sucessful. </p>        

<?php 
echo "<a href=property.php><input type=button value=\"Return to list\"></a>";
}
}
?>
</body>
</html>

 

 

i am getting the message

 

 

Notice: Undefined index: image in c:\web\server\addProperty.php on line 81

 

Notice: Undefined index: image in c:\web\server\addProperty.php on line 82

ERROR: Could Not Move File into Directory

 

What is wrong with this code can anyone please help me out...

Link to comment
https://forums.phpfreaks.com/topic/125430-solved-upload-image-problem/
Share on other sites

First change this: <form method="post" action="addProperty.php" enctype="multipart/form-data">, you need to have

enctype="multipart/form-data" if you want to upload an image.

Second : check the permission on uploads folder or add the below code

if(is_dir('uploads')){

  @chmod('uploads',0777);

}

Thrid: change "move_uploaded_file" to "copy" and see if it works.

Forth: $_POST["image"] will return NULL because the image in your code has the file property instead change the position of the INSERT block with the upload block and change the INSERT query to:

$query="INSERT INTO PROPERTY (PROPERTY_ID, PROPERTY_STREET, PROPERTY_SUBURB,

                PROPERTY_STATE, PROPERTY_POSTCODE,PROPERTY_PRICE, PROPERTY_IMAGE, PROPERTY_TYPE) VALUES

                (prop_id_seq.nextval,'".$_POST["street"]."','".$_POST["suburb"]."',

                '".$_POST["state"]."','".$_POST["postcode"]."','".$_POST["price"]."','".$_FILES["image"]["name"]."',

                '".$_POST["type"]."')";

 

 

I also want to store the image path on the image field of the table property.. please help guyzz...

 

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.