Scarleta Posted September 29, 2015 Share Posted September 29, 2015 (edited) I need urgent help! For two days I've been trying to find the source code to upload image to database and display, after trying all the codes I kept getting all sorts of errors. I'm using phpmyadmin. Fatal error: Call to undefined function finfo_open() in C:\xampp\htdocs\geology\file_insert.php on line 51 Second help needed is to display or restrict 3 latest posts only. I want to display only 3 latest posts sort by latest date posted. I'm not sure how to loop this through. Another thing is, when the user clicks on the title of a specific article, a new window will appear to display only the data that belong to it (Title, Publisher, Content...) For example, there are 3 articles (rock, mineral, salt) user clicks on Rocks, a new window appear showing all Rocks info. <?php $sql = "select * from article ORDER by article_postdate DESC"; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)) { ?> <h3><a href="#"><?php echo $row["article_title"]; ?></a></h3> <p class="byline"><span><?php echo $row["article_postdate"]; ?><br> Published By:<?php echo $row["author_id"]; ?></p></a></span></p> <p><?php echo $row["article_details"]; ?></p> <td><a href = "edit.php?article_id=<?php echo $row['article_id']; ?>">More...</a></td> <?php } ?> Edited September 29, 2015 by Scarleta Quote Link to comment https://forums.phpfreaks.com/topic/298363-display-image-restrict-posts/ Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2015 Share Posted September 29, 2015 (edited) It you would be helpful if you had posted your code (wrap in tags) and the error messages you are getting Edited September 29, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/298363-display-image-restrict-posts/#findComment-1521864 Share on other sites More sharing options...
Scarleta Posted September 29, 2015 Author Share Posted September 29, 2015 (edited) I need urgent help! For two days I've been trying to find the source code to upload image to database and display, after trying all the codes I kept getting all sorts of errors. I'm using phpmyadmin. 1) Upload & Display image of any size < 5mb 2) upload & provide click-able link for PDF size file < 10mb 3) restrict up to only 3 latest posts on a page It works by inserting the picture into database but doesn't allow me to upload more than 500kb which results in partial or no display. upload.php [code] upload.php <?php include "_database.php"; if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { $tmpName = $_FILES['image']['tmp_name']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = mysqli_real_escape_string($conn,$data); fclose($fp); // Create the query and insert // into our database. $query = "INSERT INTO picture (picture1) VALUES ('$data')"; $results = mysqli_query($conn,$query) or die("fail connect"); // Print results print "Thank you, your file has been uploaded."; echo "<a href='action.php'>main</a>"; } else { print "No image selected/uploaded"; } // Close our MySQL Link ?> <?php #to display picture code //php echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['picture1'] ).'"/>'; dont forget to add the open php and close ?> action.php This is for display, apparently, picture cannot be properly uploaded because of file size. <?php include "_database.php"; ?> <html> <head><title></title></head> <style> table tr td { border:1px solid black; } #size { display:block; } </style> <body> <form enctype="multipart/form-data" action="upload.php" method="post" name="changer"> <input name="MAX_FILE_SIZE" value="2048000000" type="hidden"> <input name='image' type="file"> <input value="Submit" type="submit"> <table > <tr> <td>ID</td> <td>picture</td> <td>display</td> </tr> <tr> <?php $link1 = "SELECT * FROM picture"; $result = $conn->query($link1) or die ("fucking"); if($result->num_rows>0){ while($row = $result->fetch_assoc()){ ?> <td><?php echo $row["ID"];?></td> <td><div id="size"><?php echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['picture1'] ).'"width="200px" height="500px"/>'; ?></div></td> <td><a href="display.php?id=<?php echo $row["ID"];?>">display</a></td> </tr> <?php } } ?> </table> </body> </html> Edited September 29, 2015 by Scarleta Quote Link to comment https://forums.phpfreaks.com/topic/298363-display-image-restrict-posts/#findComment-1521866 Share on other sites More sharing options...
Scarleta Posted September 29, 2015 Author Share Posted September 29, 2015 It you would be helpful if you had posted your code (wrap in tags) and the error messages you are getting Thanks for your message. I just posted my issues and the codes. Quote Link to comment https://forums.phpfreaks.com/topic/298363-display-image-restrict-posts/#findComment-1521867 Share on other sites More sharing options...
hansford Posted September 29, 2015 Share Posted September 29, 2015 You shouldn't be storing files in a database. Databases should store data and file systems should store files. Move the uploaded file into a directory and then place the location information to that file in the database. If you are going to be storing files in the database then you need to store it as type Blob and then you will have to write that data to a file with the correct extension for display purposes - which makes the whole operation pointless to store the file in the database in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/298363-display-image-restrict-posts/#findComment-1521912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.