www.webdeveloper.com
Results 1 to 6 of 6

Thread: Image upload in mysql

  1. #1
    Join Date
    Mar 2012
    Location
    bangalore,india
    Posts
    27

    Red face Image upload in mysql

    Hi there,
    I want to know the simplest way to upload an image in to the database using php and display it back to my web page.If any one has the simplest code then please share it with me.





    Thank You

  2. #2
    Join Date
    Aug 2012
    Posts
    8
    It's easy.

    PHP page allowing the image file to be uploaded to an uploads directory. (Ensure its a valid image file and not a shell script that could allow hackers backdoor access to your site).
    Once image is validated as true image. Store location of image in database. (e.g. - "images/image_file_name.jpg")

    then call it through the display.php page in the <img src="$img" />
    (keep in mind you have to run an SQL query to fetch the image location with a unique ID and attach it to the variable called $img.

  3. #3
    Join Date
    Oct 2009
    Posts
    658
    If you want to store the actual data in the database take this as a sample http://stackoverflow.com/questions/6...as-a-blob-type

  4. #4
    Join Date
    Mar 2012
    Location
    bangalore,india
    Posts
    27
    Thank you both of you ..

  5. #5
    Join Date
    Aug 2012
    Posts
    8
    Quote Originally Posted by manjuhugar24 View Post
    Thank you both of you ..
    Anytime mate

  6. #6
    Join Date
    Jul 2005
    Location
    faisalabad, punjab, pakistan
    Posts
    242
    PHP Code:
    $tempFileName $_FILES['attachFile']['tmp_name'];
    $file fopen($tempFileName'r');
    $content fread($filefilesize($tempFileName));
    $encryptedContent base64_encode($content); 
    you can store $encryptedContent in database, and when you want this image to display on webpage, simply use base64_decode(dbcolumn)

    enjoy man

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles