Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   need help with pointing to an ubuntu directory. Using LAMPP (https://www.cableforum.uk/board/showthread.php?t=33647734)

funkyCable 25-03-2009 11:57

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($dir1); 

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.

TheDon 25-03-2009 12:20

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.

funkyCable 25-03-2009 12:37

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.

TheDon 25-03-2009 13:06

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.

funkyCable 25-03-2009 13:26

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($dir1);
?>
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

Raistlin 25-03-2009 13:29

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:
Code:

.
..


funkyCable 25-03-2009 13:32

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

Raistlin 25-03-2009 13:36

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.

funkyCable 25-03-2009 13:45

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.

Raistlin 25-03-2009 13:51

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 :erm: :D

funkyCable 25-03-2009 13:59

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($dir1);
?>
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.

Raistlin 25-03-2009 14:06

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?

funkyCable 25-03-2009 14:15

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.

Raistlin 25-03-2009 14:16

Re: need help with pointing to an ubuntu directory. Using LAMPP
 
Does that mean you're all sorted?

Cool :) Nice on :tu:

funkyCable 25-03-2009 14:23

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.


All times are GMT. The time now is 02:06.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum