Upload picture with jquery or ajax with multiple fields

01/31/2015 13:03 mlukac89#1
Hi

I need to know how i can make form to upload picture without submiting form and get picture path in form field to insert in database here is code

so i need button next to image field "SELECT" and when i press select to choose picture from computer, image get uploaded and i get path im image field like C:\xampp\htdocs\images\users\imageblabla.jpg so i can save it into dataabse.

form html :

HTML Code:
<form action="" method="POST">
	<table width="100%" cellpadding="5" cellspacing="5" border="0" style="border:1px solid #919191;">
		<tr>
			<td width="200">Ime : </td><td><input type="text" name="ime"></td>
		</tr>
		<tr>
			<td>Prezime : </td><td><input type="text" name="prezime"></td>
		</tr>
		<tr>
			<td>Datum rođenja : </td><td><input type="text" name="dob"></td>
		</tr>
		<tr>
			<td>Mjesto rođenja : </td><td><input type="text" name="mjestorodjenja"></td>
		</tr>
		<tr>
			<td>Ime oca : </td><td><input type="text" name="imeoca"></td>
		</tr>
		<tr>
			<td>Ime majke : </td><td><input type="text" name="imemajke"></td>
		</tr>
		<tr>
			<td>Adresa : </td><td><input type="text" name="adresa"></td>
		</tr>
		<tr>
			<td>Image: </td><td><input type="text" name="image"></td>
		</tr>
		<tr>
			<td colspan="2"><input type="submit" name="dodaj" value="Dodaj"></td>
		</tr>
	</table>
</form>

form php :

PHP Code:
if (isset($_GET['page']) && $_GET['page'] == 'korisnici' && !empty($_GET['page']) && isset($_GET['action']) && !empty($_GET['action']) && $_GET['action'] == 'dodaj') {

    if (isset(
$_POST['dodaj'])) {
        if (isset(
$_POST['ime']) && 
            isset(
$_POST['prezime']) && 
            isset(
$_POST['dob']) && 
            isset(
$_POST['mjestorodjenja']) && 
            isset(
$_POST['imeoca']) && 
            isset(
$_POST['imemajke']) &&
            isset(
$_POST['adresa']) &&
            isset(
$_POST['image'])) {

            
$ime             $general->safe_input($_POST['ime']);
            
$prezime         $general->safe_input($_POST['prezime']);
            
$dob             $general->safe_input($_POST['dob']);
            
$mjestorodjenja $general->safe_input($_POST['mjestorodjenja']);
            
$imeoca         $general->safe_input($_POST['imeoca']);
            
$imemajke         $general->safe_input($_POST['imemajke']);
            
$adresa         $general->safe_input($_POST['adresa']);
            
$image             $general->safe_input($_POST['image']);

            
$dodaj $users->admin_add_user($ime$prezime$dob$mjestorodjenja$imeoca$imemajke$adresa$image);

            if (
$DBH->lastInsertId()) {
                echo 
'Korisnik dodan.';
                
header('Refresh: 2; url=index.php?page=korisnici');
            }
            else
            {
                echo 
'Korisnik nije dodan, došlo je do greške. Molimo pokušajte ponovno.';
            }

        }
    } 
01/31/2015 18:19 MrDami123#2
Quote:
Originally Posted by mlukac89 View Post
upload picture without submiting form
Trigger a function which uploads the image with a POST request after the user have sucessfully selected an image from his computer.
01/31/2015 21:44 mlukac89#3
can u give me some example because i was never do something like this and in jquery
02/01/2015 23:29 MrDami123#4
You can do this probably with PHP too. Else you just write a small javascript function which calls your PHP function.

The best way in case it actually to google. You would have your answer yesterday at 13:15.