LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-06-2013, 02:00 PM   #1
sniper8752
Member
 
Registered: Oct 2012
Posts: 264

Rep: Reputation: Disabled
php and accessign local files


I am trying to use PHP to access local files.

I have the following code:

Code:
<?php

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";
    }

    closedir($handle);
}
?>
I get this:

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

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

http://php.net/manual/en/function.opendir.php

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

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
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Kubuntu
Posts: 1,190

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
Quote:
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.
 
  


Reply


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


All times are GMT -5. The time now is 06:40 AM.

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