Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-06-2013, 02:00 PM   #1
Registered: Oct 2012
Posts: 354

Rep: Reputation: Disabled
php and accessign local files

I am trying to use PHP to access local files.

I have the following code:


if ($handle = opendir('/var/www/users')) {
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";

I get this:

Directory handle: Resource id #4 Entries: .. username .
What does that resource id #4 mean?
Old 05-06-2013, 02:13 PM   #2
Registered: Aug 2002
Posts: 16,157

Rep: Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875Reputation: 1875
It basically is the same thing as a file pointer. i.e. $handle = Resource id #4

Last edited by michaelk; 05-06-2013 at 02:32 PM.
Old 05-06-2013, 03:09 PM   #3
Registered: Oct 2012
Posts: 354

Original Poster
Rep: Reputation: Disabled
does that mean it is just pointing to a file? not sure exactly what a file pointer is. why doesn't it just substitute it with the name of the file?
Old 05-06-2013, 03:48 PM   #4
Senior Member
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
why doesn't it just substitute it with the name of the file?
You ask why converting "resource" to "string" not give you a filename? That has been programmed by PHP authors. I don't think it would be useful. You known what file/directory you opened (you just used it on the same line). On the other hand, you sometimes need to known this handle number.

If you ask why "opendir" command give you a "handle" and not a filename, because file names are inconvenient and unreliable in this situation. For example processes need to pass it to other processes. The string with file name and path can be long and every time it need to be copied byte by byte, first allocating appropriate memory for it. Better is using integer value, which coping is very, very fast for microprocessor.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
no browser open index.php files but other *.php files working gal Linux - Server 3 12-24-2012 06:40 AM
Why apache save php files to local computer when script run if php5 module disabled ? mesuutt Linux - Server 7 12-13-2011 08:22 AM
[SOLVED] Konqueror updates to local files / executing local binaries dogpatch Linux - General 1 01-12-2011 03:58 PM
After moving PHP files to /var/www they no longer are seen as hosted php files scheidel21 Linux - Server 9 03-01-2010 07:16 AM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 07:20 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:21 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration