Jump to content

arning: move_uploaded_file(): The second argument to copy() function cannot be a directory in


alexa16

Recommended Posts

File wont move to directory nor even upload to database 

 

here is my code , everything else uploads except the image 

<?php 

include('../connect.php');

if(isset($_POST['submit'])){

echo $post_title=mysqli_real_escape_string($connect,$_POST['title']);

echo $post_date=date('m-d-y');

echo $post_price=mysqli_real_escape_string($connect,$_POST['price']);

echo $post_keywords=mysqli_real_escape_string($connect,$_POST['keywords']);

echo $post_content=mysqli_real_escape_string($connect,$_POST['content']);

echo $post_image=mysqli_real_escape_string($connect,$_FILES['image']['name']);

echo $image_tmp=mysqli_real_escape_string($connect,$_FILES['image']['tmp_name']);


if($post_title=='' OR $post_price=='' OR $post_content=='' OR $post_keywords=='' OR $post_image=''){

	echo "<script> alert('None of the post fields can be left blank')</script>";

}else{    //moves uploaded image into the image file 

        move_uploaded_file($image_tmp,"../images/$post_image");

        $insert_query="INSERT INTO posts
        (post_title,post_date,post_price,post_image,post_keywords,post_content)
 VALUES('$post_title','$post_date','$post_price','$post_image','$post_keywords','$post_content')";

if(mysqli_query($connect,$insert_query)){

  echo "<script>alert('Succefully posted'); </script>";


} else "<h1> Did not work </h1>";



}








if (is_uploaded_file($_FILES['image']['tmp_name'])) {

echo "uploaded";

}else echo "could not upload";


var_dump(getcwd());




        echo "<a href='logout.php'> Log out </a> <br/>";
       echo "<a href='view_posts.php'> View Posts </a>";

?>

<?php }  ; ?> 

here is the html 

<html>

<head> 
<title> inserting new posts </title>
<link rel="stylesheet" type="text/css" href="admin_style.css">

</head>

<body>



<div id="edit_postform">

<form method="post" action="insert_post.php" enctype="multipart/form-data">

<table width="600" align="centre" border"10">

<tr>
<td> <h1> Insert New Post here </h1> </td>
</tr>

<tr>

<td> Post title <td>
<td> <input type="text" name="title" size="30"> </td>
</tr>

<tr>
<td> Post Price<td>
<td> <input type="text" name="price" size="30"> </td>
</tr>

<tr>
<td> Post keywords<td>
<td> <input type="text" name="keywords" size="30"> </td>
</tr>

<tr>
<td> Post image <td>	
<td> <input type="file" name="image"> </td>
</tr>


<tr>
<td> Post Content <td>
<td> <textarea name="content" cols="20" rows="20" size="30"> </textarea> </td>
</tr>



<tr>
<td> <input type="submit" name="submit" value="Publish now"> </td>
</tr>

</table>

</form> 
</div>


</body>
</html>

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.