php - Upload Image from different page -
i want upload image , insert database different page. want create admin panel can upload image image sider image slider in different page. it's working when form method inside index.php, when put admin.php it's not working. think need method?
can give me idea method, requirements that? i'm new php , sql.
here index.php code want show slide.
<?php //for connecting db include('connect.php'); if (!isset($_files['image']['tmp_name'])) { echo ""; } else { $file=$_files['image']['tmp_name']; $image= addslashes(file_get_contents($_files['image']['tmp_name'])); $image_name= addslashes($_files['image']['name']); move_uploaded_file($_files["image"]["tmp_name"],"gallery/" . $_files["image"]["name"]); $photo="gallery/" . $_files["image"]["name"]; $query = mysqli_query($mysqli, "insert images(photo)values('$photo')"); $result = $query; echo '<script type="text/javascript">alert("image uploaded ");window.location=\'index.php\';</script>'; } ?> <!doctype html> <html> <head> <link href="css/style.css" rel="stylesheet" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <script src="js/slider.js"></script> <script> $(document).ready(function () { $('.flexslider').flexslider({ animation: 'fade', controlscontainer: '.flexslider' }); }); </script> </head> <body> <div class="container"> <div class="flexslider"> <ul class="slides"> <?php // creating query fetch images database. $query = mysqli_query($mysqli, "select * images order id desc limit 5"); $result = $query; while($r = mysqli_fetch_array($result)){ ?> <li> <img src="<?php echo $r['photo'];?>" width="400px" height="300px"/> </li> <?php } ?> </ul> </div> </div> </body> </html>
here connect.php code.
<?php // hostname or ip of server $servername='localhost'; // username , password log onto db server $dbusername='root'; $dbpassword=''; // name of database $dbname='pegasus'; ////////////// not edit below///////// $mysqli = new mysqli($servername,$dbusername,$dbpassword,$dbname); if($mysqli->connect_errno){ printf("connect failed: %s\n", $mysql->connect_error); exit(); } ?>
and here admin.php code want upload image.
<form class="form" action="" method="post" enctype="multipart/form-data"> <div class="image"> <p>upload images , try self </p> <div class="col-sm-4"> <input class="form-control" id="image" name="image" type="file" onchange='alertfilesize();'/> <input type="submit" value="image"/> </div> </div> </form>
i solved myself putting php code in admin.php
<?php //for connecting db include('connect.php'); if (!isset($_files['image']['tmp_name'])) { echo ""; } else { $file=$_files['image']['tmp_name']; $image= addslashes(file_get_contents($_files['image']['tmp_name'])); $image_name= addslashes($_files['image']['name']); move_uploaded_file($_files["image"]["tmp_name"],"gallery/" . $_files["image"]["name"]); $photo="gallery/" . $_files["image"]["name"]; $query = mysqli_query($mysqli, "insert images(photo)values('$photo')"); $result = $query; echo '<script type="text/javascript">alert("image uploaded ");window.location=\'admin.php\';</script>'; } ?> <form class="form" action="" method="post" enctype="multipart/form-data"> <div class="image"> <p>upload images , try self </p> <div class="col-sm-4"> <input class="form-control" id="image" name="image" type="file" onchange='alertfilesize();'/> <input type="submit" value="image"/> </div> </div> </form>
Comments
Post a Comment