How to upload image and save path to database

0 votes

I have a page with some displayed images (database driven). Here is my gallery.php's source code:

<ul id="portfolio-list" class="gallery">
    <?php
        $sql="select * from eikones ";
        $res=mysql_query($sql);
        $count=mysql_num_rows($res);

        for ( $i = 0; $i < $count; ++$i )
        {
            $row = mysql_fetch_array( $res );
            $co=$i+1;
            if(isset($row[ "path" ]))
            {
                $path= $row[ "path" ];
            }

            if(isset($row[ "auxon" ]))
            {
                $auxon = $row[ "auxon" ];
            }


            if($_SESSION['role'] == "admin")
                echo "<li class=\"pink\"><a href=\"$path\" rel=\"group1\" class=\"fancybox\" title=\"Προιόν \"><img src=\"$path\" alt=\"Pic\"></a></li>\n";

        }

        ?>


</ul>

I now want to have a form where I can add a picture. This is what I'm doing, but it's ineffective:

<form enctype="multipart/form-data" action="gallery.php" method="post" name="changer">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>

<?php

include 'conf.php'; //database connect

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 


  $tmpName  = $_FILES['image']['tmp_name'];  


  $fp      = fopen($tmpName, 'r');
  $data = fread($fp, filesize($tmpName));
  $data = addslashes($data);
  fclose($fp);


  $query = "INSERT INTO eikones"; //table name = "eikones" and it has two columns named "auxon" and "path". The auxon is the id.
  $query .= "(image) VALUES ('','$data')";
  $results = mysql_query($query, $link) or die(mysql_error());

  print "DONE";

  }
  else {
  print "NO IMAGE SELECTED";
  }

?>

It says "NO IMAGE SELECTED" and nothing new comes into the database.

Jul 22, 2022 in PHP by Kithuzzz
• 38,000 points
766 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to upload and Save Files with Desired name using php?

Hello, You can try this, $info = pathinfo($_FILES['userFile']['name']); $ext = ...READ MORE

answered Nov 4, 2020 in PHP by anonymous
• 82,840 points
9,674 views
0 votes
0 answers

How to delete image form folder and database

With the code below, I'm displaying data ...READ MORE

Jul 26, 2022 in PHP by Kithuzzz
• 38,000 points
1,341 views
0 votes
0 answers
0 votes
1 answer

How to upload and delete files from dropzone.js?

Hello, For deleting thumbnails you have to enable ...READ MORE

answered Nov 4, 2020 in PHP by Niroj
• 82,840 points
10,207 views
0 votes
1 answer

How to save image from url with curl PHP?

Hello @kartik, try this: function grab_image($url,$saveto){ ...READ MORE

answered Nov 14, 2020 in PHP by Niroj
• 82,840 points
7,433 views
0 votes
0 answers

How to display image from database using PHP?

I want to display an image from ...READ MORE

May 11, 2022 in PHP by Kichu
• 19,040 points
816 views
0 votes
0 answers

PHP upload image

I have a config.php file that connects ...READ MORE

Jun 4, 2022 in PHP by Kichu
• 19,040 points
505 views
0 votes
1 answer

Why is not preferable to use mysql_* functions in PHP?

The reasons are as follows: The MySQL extension: Does ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,250 points
1,274 views
0 votes
2 answers
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP