Mendapatkan url image ketika diupload

davinci kaskus · Oct 30, 2011
selamat malam mas, saya ingin menanyakan bagaimana caranya memasukkan nama image ke dalam database. berikut kode php nya
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
//we verify if the image has been uploaded, and print error instead
if (!$copied) 
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
// the new thumbnail image will be placed in images/thumbs/ folder
$thumb_name='images/thumbs/thumb_'.$image_name;
// call the function that will create the thumbnail. The function will get as parameters 

$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}}	}}

//If no errors registred, print the success message and show the thumbnail image created
if(isset($_POST['Submit']) && !$errors) 
{
echo "<h1>Thumbnail created Successfully!</h1>";
echo '<img src="'.$thumb_name.'">';
}

?>
<!-- next comes the form, you must set the enctype to "multipart/form-data" and use an input type "file" -->

<form name="newad" method="post" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>">
<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>	

<table>
<tr valign="baseline">
<td><input type="hidden" name="url" value="<?php echo $image_name ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td><select name="id_kat">
<?php
do { 

Jadi ketika saya ingin memasukkan image baru, secara otomatis akan mengambil nama berdasarkan waktu, nah yg jadi permasalahan bagaimana caranya mendapatkan url image dan secara langsung bisa diinputkan ke dalam database.
terima kasih sebelumnya..
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Oct 30, 2011 · 0 Suka · 0 Tidak Suka
yang perlu disimpan ke database adalah nama filenya saja dan url image dibentuk saat ditampilkan.
pada kodemu bagian $image_name dan 'thumb_'.$image_name yang disimpan ke database. Tutorial http://www.myphptutorials.com/tutorials/39/membuat-galeri-foto and memperjelas.