10/10/2018, 10:49
Giúp mình lấy đường dẫn của file Upload trong PHP
Mình muốn lấy giá trị đường dẫn của file trên máy khi up load nhưng nó chỉ lấy được tên file không lấy được đường dẫn.
Code mình như sau:
index.php
upload.php
Ở trên là: $link = $_POST['upload_file'];
Code này nó chỉ hiện lên fileup không hiện lên đường dẫn là : c:.....fileup
Làm cách nào để lấy được đường dẫn vậy các bạn?
Code mình như sau:
index.php
PHP Code:
<?php
echo'
<form method="POST" action="upload.php">
<input type="file" name="upload_file" />
<input type="submit" value="Upload this file"/>
';
?>
PHP Code:
<?php
$link = $_POST***91;'upload_file'***93;;
echo '<u>Duong Dan:</u> '.$link;
?>
Code này nó chỉ hiện lên fileup không hiện lên đường dẫn là : c:.....fileup
Làm cách nào để lấy được đường dẫn vậy các bạn?
Bài liên quan
Tuy nhiên, nếu muốn, bạn có thể tạo 1 field ẩn, dùng js lưu giá trị đường dẫn và truyền cho server xử lý.
bạn có thể viết dùm mình đoạn scrip nhw bạn nói để mình tham khảo được không, mình cảm ơn bạn nhiều.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>This is a test</title>
<script language="javascript" type="text/javascript">
function getPath() {
var Form = document.forms['frm_upload'];
var inputName = Form.elements['file1'].value;
var imgPath = inputName;
Form.elements['file_src'].value = imgPath;
}
</script>
</head>
<body>
<form name="frm_upload" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" onSubmit="getPath();">
<input name="file1" type="file"><br>
<input name="file_src" type="hidden" value="">
<input name="btn_submit" type="submit" value="show path">
</form>
<?php
echo stripslashes($_POST["file_src"]);
?>
</body>
</html>
nguồn: http://www.allquests.com/question/26...aded-file.html
Hic, vertrigo thì chạy nhừng xampp với wamp và up lên host thì không chạy.
Cảm ơn bạn nhiều.