[TYPO3-dev] POST the path from a <input type="file">?

Christopher Torgalson bedlamhotel at gmail.com
Mon Dec 4 01:35:20 CET 2006


Hi,

On 12/3/06, Matthias Stuebner <news at stuebner.de> wrote:
> Hello group,
>
> in a BE module I write I select a file using:
>
> <input type="file" size="50" name="import_file" />
>
> which shows the path of that file then. But when I send this form I didn't
> find any way to read more than the filename. So how to get the full path?
>
> $filename = $_POST['import_file'];
> $filename = $_FILES['import_file']['name'];
>
> Both of the above return the name only, not the path.
>
> Could someone point to the right direction please?


I could be wrong, but I doubt this is possible. I can't see any reason
why a user-agent /would/ transmit the local path to a selected file as
part of the post. Obviously it should transmit the file name and
contents, but why the path? Generally speaking, the local directory
structure is no concern of the remote machine...

Anyways, if you really need this value and you can't get it with PHP,
you can do a bit of javascript jiggery-pokery to copy the path into a
hidden field--given that the BE is a js monster anyhow, I don't see
any big problems with this method:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>JS File Test</title>
	<script type="text/javascript">
		function passValue() {
			document.getElementById('filePathContainer').value =
document.getElementById('filePath').value;
		}
	
		function showValue() {
			alert(document.getElementById('filePathContainer').value);
		}
	</script>
</head>
<body>
	<form id="foo" method="post" action="" target="_self">
		<div>
			<input type="file" id="filePath" onblur="passValue();">
			<input type="hidden" value="" id="filePathContainer">
			<input type="submit" value="submit" onclick="showValue();return false;">
		</div>
	</form>
</body>
</html>


-- 
Christopher Torgalson




More information about the TYPO3-dev mailing list