Have an account? Sign in
Login  Register  Facebook
Upload image and add image path on db
Hello there!
I have a form that add some information on mysql db but i need a way to upload an image with this form too and the path of the image to be inserted on the db. I don't know how to do it. Can you help me please?

I didn't create any field for image bcz i don;t know what type of field it should be and i did not have any db field for image bcz i don;t know how it should be. I mention that i don;t want to upload the image on my db; i need only the path of the image.

On the edit page i need to show the image with image tag <img src.... /> and the same field with browse option for edit it.

Thank you very much and hoping that you can help me!
-----------edit-----------
Thank you for your reply and helping me. I have made those changes but i dunno what variable i should put on sql insert statement for the img field. What i have now is:

$sql = "INSERT INTO lajme (KatLajmeID, LajmeEmri, LajmeLink,
                             LajmeIntro, LajmeTxt, LajmeAktiv,
                              LajmeTag, LajmeVideo, LajmeImg)
    	VALUES ('$KatLajmeID', '$LajmeEmri', '$LajmeLink',
         '$LajmeIntro', '$LajmeTxt', '$LajmeAktiv',
          '$LajmeTag', '$LajmeVideo', '$LajmeImg')";
// LajmeImg - is the image field on db
// $LajmeImg - is the variable that i putted and didn't worked. 
I tried to use like image variable $file but it didn't worked too :( At form process i putted:
include ('includes/uploader.class.php');
    $uploader = new uploader();
    // Setting properties then Uploading the image
    $uploader->destDir = "D:/Program Files/VertrigoServ/www/oldi/imazhet/artikuj/";
    $uploader->upload($_FILES['image']);

The form uploads the image correctly but it didn't insert the path on the db :(
Started: September 19, 2011 Latest Activity: June 8, 2018 image img browse form path
5 Answers
Any Danger In Using Expired Amoxicillin Forum Cialis 20mg <a href=http://cialiviag.com>cialis</a> Cephalexin For Dental Infections Std Pills Online Cialis Generico E Legale

Posted: Ellgaibra
In: June 8, 2018

Hello there. I'm posting here again bcz i need a little help on the modification you did on script. You made the name to be generate automatically by base64. What i need is a way to make the name of the image like this:
its_real_name_base64Code
In this way i'll have google readable images and unique id images. Can you help me on this please?

Thank you!

Posted: Kleidi
In: September 19, 2011

your code is not clear its not organised
  • you have to upload the img when isset(post)
  • like
    if(isset($_POST['do_edit'])) {
    
    if(isset($_FILES['LajmeImg'])){
    //upload here
    }
    
    }
  • after upload without errors you have to update the mysql
  • and you can use extract($_POST) and $LajmeID instead of $LajmeID = $_POST['LajmeID']

Posted: MacOS
In: September 19, 2011

Image Variable should be
$LajmeImg = $_FILES['image']['name'];

Posted: xtremex
In: September 19, 2011

Thank you xtremex for your reply. It worked thanks to you ;) What i was looking around now is how to make autoname now. :( I changed the autoName variable to true but it didn't renamed the image on upload. Any help on this? Thank you ;)
September 19, 2011

it seem the class has no autoName support
September 19, 2011

The class that i have downloaded writtes at the top something like public $autoName = true; :(
September 19, 2011

yes but in the source its not used :) this is an error from the coder
September 19, 2011

And how to make it working? If i upload 2 different images with the same name, the last one will rewrite the first image :(
September 19, 2011

now the class support this feature i made some changes on it just use autoName = true and then when save the name in mysql use $uploader->source['name'] to save the random name - now go the class downloading page agian
September 19, 2011

Thank you very much Jooria. It works great thanks to you. It generates unique names now :D Thanks!
September 19, 2011

thank you my friend but i think the class owner will kill me if he know what i did, lol :)
September 19, 2011

:P ... Eh, it's an open source and you can do what you need with it :P
September 19, 2011

we can use uploader class
now you should enctype the form
<form method=\"post\" enctype=\"multipart/form-data\">
and add the file input
<input name=\"image\" type=\"file\" size=\"20\" />
and when click \'Vazhdo\' you sould use this php code
include (\'uploader.class.php\');
    $uploader = new uploader();
    // Setting properties then Uploading the image
    $uploader->destDir = \"images/\";
    $uploader->upload($_FILES[\'image\']);

and in your datebase table you should make new field to store the img name to get it from the server
and look at the class function to make the edit page by delete and other function

Posted: MacOS
In: September 19, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer