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
PHP Code:
<?php
echo'
<form method="POST" action="upload.php">
<input type="file" name="upload_file" />  
<input type="submit" value="Upload this file"/>
'
;
?>
upload.php
PHP Code:
<?php
$link 
$_POST***91;'upload_file'***93;;
echo 
'<u>Duong Dan:</u> '.$link;
?>
Ở 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?
thuyduongcd viết 13:04 ngày 10/10/2018
Fullpath là phần do client quản lý, server không có quyền biết vì lý do bảo mật.
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ý.
star_night viết 12:58 ngày 10/10/2018
Được gửi bởi thuyduongcd
Fullpath là phần do client quản lý, server không có quyền biết vì lý do bảo mật.
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ý.
Cảm ơn bạn đả trả lời giúp mình.
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.
vnntech.com viết 12:55 ngày 10/10/2018
bác thử cái này xem

<!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
star_night viết 12:49 ngày 10/10/2018
Được gửi bởi vnntech.com
bác thử cái này xem

<!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
Cảm ơn bạn nhiều, nhwng mình chạy thử nó vẫn ra file không ra full đường dẫn.
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.
thuyduongcd viết 12:58 ngày 10/10/2018
Cái này chỉ chạy trên IE
Bài liên quan
0