Jump to content

opendir() on main dir


Twentyoneth

Recommended Posts

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.
Link to comment
Share on other sites

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")

[code]$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;

           }[/code]

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"?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[code] opendir('./');[/code]

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.