need help with pointing to an ubuntu directory. Using LAMPP
25-03-2009, 11:57
|
#1
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
need help with pointing to an ubuntu directory. Using LAMPP
Hi
I'm trying to create a php script that will read all directorys/files from a specific folder and place the paths into a mysql db.
As I am new to PHP/apache I wondered how I could do this. I see php has a scandir function and I tried the following bit of code which returned some files but I have no idea where its getting its info.
PHP Code:
<?php $dir = '/tmp'; $files1 = scandir($dir); $files2 = scandir($dir, 1);
print_r($files1); print_r($files2); ?>
I did a the normal LAMPP installation on my ubuntu machine. I know my installation is stored under /opt/lampp and my webpages are under /opt/lampp/htdocs.
My question is how do I point to another directory in PHP. I want to point to /opt/lampp/web_site_copy/pictures
Do i need to make changes to my apache config file and if so how do i do it?
I looked throught my phpinfo() and doc_root is not specifed and neither is user_doc.
Thanks for your help.
|
|
|
25-03-2009, 12:20
|
#2
|
|
Inactive
Join Date: May 2007
Posts: 1,567
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
You should just be able to use the absolute path, so setting $dir to /opt/lampp/web_site_copy/pictures should let php see them.
The real question is what you then want to then do with the paths?
If as I suspect you want to use them to create a page of links to them or some such so as you can serve the files from a webpage then yes, you'll need to alter your apache config so as your DocumentRoot is /opt/lampp/web_site_copy/ or store the pictures under /opt/lampp/htdocs/pictures which is the easier solution.
|
|
|
25-03-2009, 12:37
|
#3
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Thanks that worked perfectly.
I am hoping to do some AJAX and fetch the next/previous pictures. Do you think its worth storing the paths in a table or just keep using the scandir and loop through the directory/files in the array? I have over 6gigs of pictures and videos to follow.
A shiney is on its way.
|
|
|
25-03-2009, 13:06
|
#4
|
|
Inactive
Join Date: May 2007
Posts: 1,567
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Using scandir every time and building the array will give a pretty significant performance hit, so using a table would probably be the easiest way to do it.
Then you'd just need a separate script that you run when you've added pictures to the directory to add them to the table.
|
|
|
25-03-2009, 13:26
|
#5
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
What if a picture has been removed or the link in the table is old as the file has been moved to another location?
Do you know if you can create sceduled jobs in mysql like you do with ORACLE?
So I should perhaps have a temp directory that I use to pick up the files/directories
create a reference and store it in the table and once this is done successfully move it to the relivant permanent folder where the image will reside.
---------- Post added at 14:26 ---------- Previous post was at 14:22 ----------
I'm trying to determine whether the path is part of a directory or a file.
PHP Code:
<?php $dir = '/opt/lampp'; $files1 = scandir($dir); $files2 = scandir($dir, 1); ?> Directory <br /> <?php foreach ($files1 as $fileobject){ if (is_dir($fileobject)){ echo "$fileobject<br>"; } } ?> Files:<br /> <?php foreach ($files1 as $fileobject){
if (is_dir($fileobject)==FALSE){ echo "$fileobject<br>"; } } ?>
Under the directory I get "." and ".." and under files I get all the files and directories. I tried the is_file() function and that did not help neither
|
|
|
25-03-2009, 13:29
|
#6
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
"." is the file system's internal reference to the folder that you're currently in.
".." is the file system's internal reference to the parent folder for the folder that you're currently in.
---------- Post added at 14:29 ---------- Previous post was at 14:28 ----------
If you go to a command prompt and type dir you will get a listing of the directory contents, and should see that the first to entries are:
|
|
|
25-03-2009, 13:32
|
#7
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Thanks Rob I figures that one out but what is puzzling me is the fact that it says that
/opt/lampp/etc/ is a file when it should be a directory
|
|
|
25-03-2009, 13:36
|
#8
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
That's because in Linux everything is treated as a file
Linux doesn't really deal with file objects and directory objects, it just deals with different types of file object.
'Directories' are actually nothing more than a file that points to other files.
|
|
|
25-03-2009, 13:45
|
#9
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
I see sorry I'm originally from a windows background and used to use DOS back in the day so I do remember all the cd.. commands etc.
If thats the case what method could I use to determine whether the file is a directory or a file. I need to know this so that if its a directory it need to cd to that directory and start the go through all that directories contents. I see theres a filetype() function but that seems to break when the filetype is not a dir.
|
|
|
25-03-2009, 13:51
|
#10
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
I'm not familiar with the functions that you're using, but is there anything in the output of the function you're using to list the directory content that you could use to determine what's a directory and what isn't?
Failing that, is there a function that you can use to get the size of the object? If it has a size of 0 (zero) it's probably a directory, anything other than that and it's a file.
I say probably because it's possible to get a file with zero size, but unlikely.....maybe
|
|
|
25-03-2009, 13:59
|
#11
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Good thinking about the 0 file size
I busy looking through these functions http://www.w3schools.com/php/php_ref_filesystem.asp
PHP Code:
<?php $dir = '/opt/lampp'; $files1 = scandir($dir); $files2 = scandir($dir, 1); ?> Directory <br /> <?php foreach ($files1 as $fileobject){ if (is_dir($fileobject)){ echo "$fileobject<br>"; } } ?> Files:<br /> <?php foreach ($files1 as $fileobject){
if (is_dir($fileobject)==FALSE){ echo "$fileobject<br>"; } } ?> File type:<br /> <?php foreach ($files1 as $fileobject){
//if (is_dir($fileobject)==FALSE){ echo "$fileobject : " . filetype($fileobject) . "<br>";
}
?>
this is my testing code at the moment.
|
|
|
25-03-2009, 14:06
|
#12
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Does the $fileobject variable just give you a file/directory name?
---------- Post added at 15:06 ---------- Previous post was at 15:03 ----------
When you say filetype() breaks things when they're not a directory what results do you actually get?
|
|
|
25-03-2009, 14:15
|
#13
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
You were right it was just a filename/directory name not an actual path.
PHP Code:
<?php $dir = '/opt/lampp'; $files1 = scandir($dir); ?> Directory <br /> <?php foreach ($files1 as $fileobject){ $file = $dir . "/" . $fileobject; if (is_dir($file)){ echo "$fileobject<br>"; } } ?> <br /><b>Files:</b><br /> <?php foreach ($files1 as $fileobject){ $file = $dir . "/" . $fileobject; if (is_file($file)){ echo "$fileobject<br>"; } } ?> <br /><b>File type:</b><br /> <?php foreach ($files1 as $fileobject){ $file = "/opt/lampp/" . $fileobject; echo "$fileobject : " . filetype($file) . "<br>"; } ?> <br /><b>File Sizes:</b><br /> <?php foreach ($files1 as $fileobject){ $file = "/opt/lampp/" . $fileobject; echo filesize($file) . "<br>"; } ?>
This clearly shows what is a directory and what is a file.
|
|
|
25-03-2009, 14:16
|
#14
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Does that mean you're all sorted?
Cool  Nice on
|
|
|
25-03-2009, 14:23
|
#15
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Yip thanks for your help.
Unfortunately cable forum not allow me to add to your reputation because I've already given you some reputation from one of my other queries.
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 02:20.
|