I have problem with getting name of image.
I have use following code to update image under upload folder.
I am updating image path with $image= time()."_".strtolower(str_replace($tokan, "" ,$file));
time function use to add time stamp before image name.
but problem is only time_ path update I did not get the file name in that.
for example:
if I am browsing image using file type like sunset.jpg
I only get “time_” not sunset.jpg…
<?php
$host="localhost";
$username="root";
$password="";
$db="training_swapnil";
$tbl="gallary";
$tb="album";
$img_id=$_GET['id'];
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
$q="SELECT * FROM $tbl WHERE eid='$img_id'";
$r=mysql_query($q);
$rw= mysql_fetch_assoc($r);
echo $img=stripslashes($rw['image']);?>
<form name="update_img">
<table border="0"><tr>
<td><label>Uploaded Image:</label></td>
<td><?php echo "<img src=\"uploads/$img\" width=\"150\" height=\"150\" />";?></td></tr>
<tr><td><label>Upload New Image:</label></td><td> <input type="file" name="file" id="file"/></td></tr>
<tr><td><input type="submit" name="submit" value="upload"></td></tr>
<?php
echo"here in post";
$file=$_POST['file'];
//$str=$HTTP_POST_FILES['file']['name'];
echo "str file =$str";
$tokan = array(" ", "'","`","’");
//$image= time().".$file.";
$image= time()."_".strtolower(str_replace($tokan, "" ,$file));
$path= "uploads/".$image;
echo "path using file=$image";
$sql="UPDATE gallary set image='$image', path='$path' WHERE eid='$img_id'";
echo $sql;
$res=mysql_query($sql);
$res=mysql_query($s);
if($res>0)
{
if($file !=none)
{ if(copy($HTTP_POST_FILES['file']['tmp_name'], $path)) { //header("location:viewalbum.php");
}
else
{
echo "Error";
}
}
}
?>
</table></form>
Replace
$file=$_POST['file']by$file=$_FILES['file']['name']More details here : http://php.net/manual/en/features.file-upload.post-method.php