$_FILES path and image name as a string.
Can this be done from a form? If so, how?
Sorry for the very short question, I've got to walk the dog
spence
| SitePoint Sponsor |


well put the dog down and explain yourself properly!
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!





ok.
Once an image file (jpeg) has been selected to be uploaded can the path and the filename be converted to a string?
So the user selects a file in "c:/my photos/me.jpg" for example, through the form.
Then onto the next page, to make sure the user has selected the correct path, etc... I was after displaying the path and filename only.


I am pretty sure you cant get the full path of the users selected folder as it poses a security risk.
I wonder if you could use javascript to grab it using DOM...?
hmmm, some testing required....
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!


ok, well it appears you can.....
Returns an alert with the path in it..... coolPHP Code:<script type="text/javascript">
function getValue() {
var textSet = document.testForm.uploadFile.value;
alert(textSet);
}
</script>
<?php
echo '<pre>';
print_r($_FILES);
echo '</pre>';
?>
<form name="testForm" id="testForm" action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploadFile"><br />
<input type="submit" name="submit" onClick="getValue();">
</form>![]()
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!


Ok so this got me thinking....
Puts the path into a hidden field onClick of the file input. this then gets sent through the POST array.PHP Code:<script type="text/javascript">
function getValue() {
var textSet = document.testForm.uploadFile.value;
document.testForm.testFile.value = textSet;
}
</script>
<?php
echo '<pre>';
print_r($_FILES);
print_r($_POST);
echo '</pre>';
?>
<form name="testForm" id="testForm" action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploadFile" onClick="getValue();"><br />
<input type="hidden" name="testFile" >
<input type="submit" name="submit">
</form>
You would need to run stripslashes on the value as php add them automatically
C:\docs\spike
becomes
C:\\docs\\spike
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!


I wouldnt if i hadn't been hamering DOM for a project I am currently working on![]()
Mike Swiffin - Community Team Leader
Only a woman can read between the lines of a one word answer.....
I started out with nothing... and still got most of it left!
Bookmarks