Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:14:44+00:00 2026-06-17T04:14:44+00:00

I have a problem to display pictures that can be uploaded on my website.

  • 0

I have a problem to display pictures that can be uploaded on my website. During the upload process I change the name of the file, store the picture in a folder and the file name in a database. I present my code below. Many thanks in advance to those who will have a look:

the form to upload the picture:

<form method="post" action="PicPost.php" enctype="multipart/form-data">
 <label for="Pic">Upload your pic: (JPG, JPEG PNG ou GIF  | max. 1 Mo) :</label><br />
     <input type="hidden" name="maxsize" value="1048576" />
     <input type="file" name="Pic" id="Pic" />

 <p>
   <label>Tags
   <input type="text" name="Tags" id="Tags" />
   </label>
   <br />

   <input type="submit" name="submit" value="Submit" />
      </p>
  </form> 

The code to complete the upload in PicPost.php:

 <?php
$maxsize = '1048576';

 if ($_FILES['Pic']['error'] > 0) $erreur = "Error";

 if ($_FILES['Pic']['size'] > $maxsize) $erreur = "The file is too big";

 $extensions_valides = array( 'jpg' , 'jpeg' , 'gif' , 'png' );
 $extension_upload = strtolower(  substr(  strrchr($_FILES['Pic']     ['name'], '.')  ,1)  );
  if ( in_array($extension_upload,$extensions_valides) ) echo "Correct extension";

 $name = md5(uniqid(rand(), true));

 $resultat = move_uploaded_file($_FILES['Pic']['tmp_name'],$name);
 if ($resultat) echo "Upload successful";

 try
 {
 $bdd = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
 }
 catch (Exception $e)
 {
die('Erreur : ' . $e->getMessage());
 }
 $req = $bdd->prepare('INSERT INTO picdb (Picture, Tags)
 VALUES(?, ?)');
 $req->execute(array($name, $_POST['Tags']));

The code to search a picture in the database through tags:

<form id="form1" name="form1" method="post" action="SearchPost.php">
<label>
<input type="text" name="Search" id="Search" />
</label>
<label>
<input type="submit" name="Submit" id="Submit" value="Search" />
</label>
</form>

The code to display the picture searched in SearchPost.php:

try
{
$bdd = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}


 $reponse = $bdd->query('SELECT Picture FROM picdb WHERE
 Tags=\''.$_POST['Search'].'\'');

  while ($donnees = $reponse->fetch())


 echo "<img src=".$donnees['Picture']."/>";

 $reponse->closeCursor(); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:14:46+00:00Added an answer on June 17, 2026 at 4:14 am

    Store the new filename in the database, in another field, or the one you have already.

    You’re storing the original filename

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to display Datetime in my gridview, the problem is that while I
I have a website where users can upload their photos and I'd like to
I have built a layout that can display a picture on three different areas.
I'm working on a website that hosts music, pictures, and videos. I currently have
The problem that I have is that I want to display a map of
I have this problem having to display my jasper report on my grails application.
I have a problem with the display of my popover. After initWithContentViewController: and presentPopoverFromBarButtonItem:permittedArrowDirections:animated:
I have a problem with li , when I take li in inline display
i have a problem with VIMEO video . I want to display it in
I have an strange problem using two borders. I use them to display video

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.