10/10/2018, 09:49 
               
            giúp đỡ "lấy tên ảnh khi upload", javascript
               
					mình có đoạn code như sau : 
/////////////////////////
<script>
function ham(x)
{
//var x=document.getElementById("mot").value;
//alert(x);
document.getElementById("hai").innerHTML=x;
}
</script>
<form action="">
<input type="file" id="mot" onchange="ham(this.value)">
</form>
<span id="hai"></span>
//////////////////////////
trong firefox , nó đã lấy được tên ảnh trước khi up, nhưng ie thì không , có cách nào hông các bạn
            
         /////////////////////////
<script>
function ham(x)
{
//var x=document.getElementById("mot").value;
//alert(x);
document.getElementById("hai").innerHTML=x;
}
</script>
<form action="">
<input type="file" id="mot" onchange="ham(this.value)">
</form>
<span id="hai"></span>
//////////////////////////
trong firefox , nó đã lấy được tên ảnh trước khi up, nhưng ie thì không , có cách nào hông các bạn
            Bài liên quan
         
                
            




if(isset($_POST['txtTitle']))
{
$albumId = $_POST['cboAlbum'];
$imgTitle = $_POST['txtTitle'];
$imgDesc = $_POST['mtxDesc'];
$images = uploadImage('fleImage', GALLERY_IMG_DIR);
if ($images['image'] == '' && $images['thumbnail'] == '') {
echo "Error uploading file";
exit;
}
$image = $images['image'];
$thumbnail = $images['thumbnail'];
if (!get_magic_quotes_gpc()) {
$albumName = addslashes($albumName);
$albumDesc = addslashes($albumDesc);
$imgPath = addslashes($imgPath);
}
$sql = "INSERT INTO tbl_image (im_album_id, im_title, im_description, im_image, im_thumbnail, im_date)
VALUES ($albumId, '$imgTitle', '$imgDesc', '$image', '$thumbnail', NOW())";
mysql_query($sql) or die('Error, add image failed : ' . mysql_error());
echo "<script>window.location.href='index.php?page= list-image&album=$albumId';</script>";
exit;
}
// Tao Danh Sach Album
$sql = "SELECT al_id, al_name
FROM tbl_album
ORDER BY al_name";
$result = mysql_query($sql) or die('Error, get album list failed : ' . mysql_error());
$albumList = '';
$selectedAlbum = isset($_GET['album']) ? $_GET['album'] : '';
while ($row = mysql_fetch_assoc($result)) {
$albumList .= '<option value="' . $row['al_id']. '"';
if ($row['al_id'] == $selectedAlbum) {
$albumList .= ' selected';
}
$albumList .= '>' . $row['al_name'] . '</option>';
}
?>
mà bếu có kết nối thì cũng cho mình bít kết cấu table , datbase chứ , như vậy thì sao chạy code được
đúng là co ra nhưng nó ra như thế này "C:\fakepath\5.jpg" (co C:\fakepath\ ma lẽ r chỉ là 5.jpg
--> dan den khong load ảnh dc)
mình thử :
///////////////////////////////
<script>
function ham(x)
{
//var x=document.getElementById("mot").value;
//alert(x);
x=x.replace(/C:\fakepath\/,"");
document.getElementById("hai").innerHTML=x;
}
</script>
<form action="">
<input type="file" id="mot" onchange="ham(this.value)">
</form>
<span id="hai"></span>
///////////////////////////////////
cũng không được , mong giúp đỡ
Nếu muốn lấy cái file name để làm gì đó thì cách tốt nhất là viết thêm vài dòng tách cái chuỗi value đó ra.
Với lại mình cũng chưa hỉu ý bạn , bạn nói rõ hơn được hông?
Đại loại như thế này:
function ham(x) { temp = x.split('\\'); x = temp[temp.length-1]; document.getElementById("hai").innerHTML=x; }đúng là mình còn non quá