Page 1 of 1
How to get COmplete path through BROWSE BUTTON
Posted: Wed Dec 06, 2006 6:30 am
by eshban
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello,
I am facing a little problem in PHP.
There is a BROWSE BUTTON on the form, when i press it and select any file like 'C:\newfolder\abc.txt', it returns me the selected file name.
How can i retrieve the complete path i.e.
c:\newfolder\abc.txt
plz help
Below is the little code
Code: Select all
<html>
<head>
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<? print "<br>".basename($_FILES['file']['name']); ?>
<input type="submit" value="submit">
</form>
</body>
</html>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Dec 06, 2006 6:39 am
by CoderGoblin
The browse button functionality when uploading is defined by your browser and cannot be changed for security reasons. The PHP handling the uploaded file deals only with copy of the actual file, it should never need the path information.
Posted: Wed Dec 06, 2006 6:42 am
by JayBird
If your trying to upload a file like that, then it isn't possible. Think of the security implications!!
Posted: Wed Dec 06, 2006 7:00 am
by eshban
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Here is the solution
Code: Select all
<?
print "PATH = ".$_REQUEST['path'];
?>
<form method="post" enctype="multipart/form-data" onSubmit="this.path.value = this.myfile.value;">
<input type="file" name="myfile">
<input type="hidden" name="path">
<input type="submit" name="submit">
</form>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Dec 06, 2006 11:37 am
by feyd
..and here's how to break it: turn off Javascript.
Posted: Wed Dec 06, 2006 3:07 pm
by amir
feyd, you are right.
what do you say about AJAX?
Thanks!
Posted: Wed Dec 06, 2006 3:19 pm
by ok
AJAX is JS!!!
!?
Posted: Wed Dec 06, 2006 3:26 pm
by PrObLeM
ok wrote:AJAX is JS!!!
WHAT?!?!?! thats just crazy talk!
Posted: Wed Dec 06, 2006 3:29 pm
by amir
OK, Thanks FYI!
feyd said
..and here's how to break it: turn off Javascript.
There are lots of sites today in AJAX and if we turn off the JS, they dont work so what do you sujjest whether we should work in AJAX or not?
Thanks.
Posted: Wed Dec 06, 2006 3:37 pm
by feyd
When asked that sort of question my response is almost 100% the same: use unobtrusive techniques. Write the pages so they will work without Javascript enabled. If you want to do something that will require Javascript it better be damn important. Use Javascript to alter the page content to suit how you want it to look for browser that have it enabled.
It's really hard to justify to me that a site actually requires Ajax or Javascript for that matter. For the most part they require it on a lot of sites because the developers were/are lazy. By requiring Javascript and Ajax you can significantly reduce the demographic size for your application. Sometimes that's okay, but most often you want it to work for as many people as possible. That's why some of us still write pages that will work in browsers as far back as say Netscape 2 or Mosaic or even farther back. Not to mention making sure that text based browsers such as lynx and links work with the site well. Then there are the disabled persons out there.. etcetera, etcetera. It's about accessibility.
Touchy subject I guess.

Posted: Wed Dec 06, 2006 3:38 pm
by ok
feyd is right about his comment.
But, I think that you simply need to denied access to your site from users who don't have JS enabled:
Code: Select all
<noscript>This site requires JavaScript.</noscript>
Posted: Wed Dec 06, 2006 3:42 pm
by feyd
ok wrote:feyd is right about his comment.
But, I think that you simply need to denied access to your site from users who don't have JS enabled:
Code: Select all
<noscript>This site requires JavaScript.</noscript>
Deny access to a site because it then can't read the path my
private file system has for a file I'm uploading?
Sound a bit silly to you?
Posted: Wed Dec 06, 2006 3:46 pm
by ok
feyd wrote:Deny access to a site because it then can't read the path my private file system has for a file I'm uploading?
Sound a bit silly to you?
Yes! It is very silly, but I just offered an idea.
BTW, why do you want to know the path???