Jump to content


Photo

opendir() on main dir


  • Please log in to reply
8 replies to this topic

#1 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 25 March 2006 - 10:00 PM

I am trying to use opendir() on my main directory [http://site.com] but I can only get it to work on other dirs inside my main directory [articles/], how do I tell opendir() to read from the main directory?

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 25 March 2006 - 10:30 PM

You should always post your code to help members on this forum help you.

You should really be using path names and not URL's. See:

[a href=\"http://us2.php.net/manual/en/function.opendir.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.opendir.php[/a]


p.s. The directories must have the correct permissions to allow the PHP script to open a directory.


#3 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 25 March 2006 - 11:27 PM

ok, I have an opendir() command, it will only let me use directories off of my main directory, like "articles/" and "images/", but I want to have it open my main directory, [a href=\"http://site.com\" target=\"_blank\"]http://site.com[/a], not site.com/articles/. Here is the code, maybe someone could give an easier way to go about this.

zipit.php (in "zipclass" directory with "zipfile.php")

$UID = $HTTP_COOKIE_VARS['UID'];

if ($UID == '1') {

include('zipfile.php');



if ($_POST['submit']) {
   $directory = opendir('http://site.com');

   while ($file = readdir($directory)) {

            $file_array[] = $file;

           }

That is just a segment of my code, is there something like a php phrase that tells it the base directory of the site? Or something like "../" to tell it to open the directory before "zipclass"?

#4 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 28 March 2006 - 08:42 AM

This code is used for the zip class, I am trying to provide my main directory to be zipped, but I cant get it to open any directory and save the files.

#5 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 30 March 2006 - 09:29 PM

This is the class off of zend I do believe. Which creates a zip file.
[a href=\"http://nicotinejunkie.cv.vc/zipclass/code1.txt\" target=\"_blank\"]code1[/a]
This is my code, which adds files to the zip.
[a href=\"http://nicotinejunkie.cv.vc/zipclass/code2.txt\" target=\"_blank\"]code2[/a]

The problem is, no matter where I set the opendir() to, it wont add any files. My main objective is to add all of the files in my entire site to this zip file, I dont know how to go about it. But I cant even get it to add files from one directory on my site.

These two files are in 'zipclass' directory (http://site.com/zipclass/), and even upon moving them to my main directory (http://site.com/), I get no files added to the zip. What am I doing wrong? And is there any hints as to how I can add all files from all directories. And if possible how to keep the structure of directories and which files go in which (not a must).

Thanks.

#6 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 30 March 2006 - 11:38 PM

opendir('./');

Use relative paths not URLs.

./ = current directory
../ = parent directory
../otherdirectory/ = directory on same level in tree with the current one
subdirectory/ = a directory inside of the current one.

You get the idea...I use the trailing slash because it makes it easy if you set a variable like $path = "subdirectory/"; then opendir() can open it and if you have a particular file like file.txt for example you can simply say $filenameandpath = $path."file.txt"; It could be done by remembering the '/' between $path and file.txt, so it really six of one half a dozen of the other, but this is just my prefered method.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#7 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 30 March 2006 - 11:44 PM

I have tried '../ ' to get to the parent directory, but it wont add any files to the zip.
I have also tried '../images' and '../images/' and none of those worked.
I have also moved my files to the parent directory and tried 'images/' and nothing, for some reason it wont add any files to the zip. I dont know what is wrong with my code to add files to the zip, and I'm not sure if ../ to the parent directory will add all the files on my entire site, with directories and subdirecties.

#8 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 03 April 2006 - 03:14 AM

Anyone?

#9 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 03 April 2006 - 06:06 AM

It will only add them if you have the code setup to parse sub-directories. Without seeing more of your code I don't think I can provide a solution to your problem. Personally, I don't use compression to make back-ups of servers. I use a cron job setup to make a copy every night at midnight from each of my or my clients' servers.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users