How to get COmplete path through BROWSE BUTTON

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

How to get COmplete path through BROWSE BUTTON

Post by eshban »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

If your trying to upload a file like that, then it isn't possible. Think of the security implications!!
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

Post by eshban »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

..and here's how to break it: turn off Javascript.
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

feyd, you are right.
what do you say about AJAX?
Thanks!
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

AJAX is JS!!!
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

!?

Post by PrObLeM »

ok wrote:AJAX is JS!!!
WHAT?!?!?! thats just crazy talk!
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. :oops:
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post 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???
Post Reply