![]() |
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:
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. |
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. |
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. |
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. |
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:
|
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:
. |
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 |
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. |
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. |
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 |
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:
|
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? |
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:
|
Re: need help with pointing to an ubuntu directory. Using LAMPP
Does that mean you're all sorted?
Cool :) Nice on :tu: |
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. |
Re: need help with pointing to an ubuntu directory. Using LAMPP
No worries, just glad you're sorted :tu:
(actually I'm secretly surprised I was able to help at all, I know nothing about PHP :eek: :erm: :D ) |
Re: need help with pointing to an ubuntu directory. Using LAMPP
Quote:
One option is to manually delete the row in the table, which will throw out the indexes but that's pretty trivial to fix, but constantly editing the table can be time consuming. The other easy option is to drop and rebuild the table anytime you make changes, this will ensure that you aren't missing any indexes, and that everything is up to date, but is the more resource heavy option. As long as you're not making changes too often I'd personally go with the less hassle 2nd option. You don't need mySQL to do scheduled jobs, you could just have a cron job running a php script that does the work for you. But even then, you don't really need to schedule it as I assume you'll only be editing the pictures yourself? so you can just run it manually once you've added or removed some pictures. Alternatively, you could use a filesystem monitoring daemon to automatically run the script when changes in the directory are detected, but that would definitely be overkill. |
Re: need help with pointing to an ubuntu directory. Using LAMPP
I was thinking along the lines of option 2 and thought if there is such a schedule/cron job then it could run over night or once a week or something when there is less traffic so I dont need to remember to do it.
|
| All times are GMT. The time now is 02:13. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum