Jump to content

Including File in Parent Folder


ShoeLace1291

Recommended Posts

Ok this is my basic folder setup:

 

localhost/

    --myprogram(directory)

        --functions.php

        --includes(directory)

                --join.php

        --photos(directory)

        --join.php

        --themes(directory)

                --default(directory)

                        --joinform_body.tpl

 

the file 'functions.php' contains a function that copies a file selected from the user's computer with a form('themes/default/joinform_body.tpl').  includes/join.php is the file that is using the copy_photo function.  What syntax would I have to use to copy the file to the photos directory?

 

copy( $photoname, "$dir" ) or

          die("There was an error uploading your photo.  Please try again later.");

 

That's my copy function where the directory should be localhost/myprogram/photos. 

$dir = "/photos";

 

How would I do that?  I tried just plain photos but it says the directory doesn't exist so I'm thinking the script thinks it's includes/photos.

Link to comment
Share on other sites

To get to a parent directory you use ".."

 

For example in the following file system

 

--mmmvomit
  +-wwwroot
  | +-index.php
  | +-profile.php
  +-img
  | +-logo.gif
  | +-annoyingani.gif
  | +-lolcat.gif
  +-error_log.txt
  +-usernames.txt

 

If I want to access 'error_log.txt' from within 'index.php', I can do it like this.

 

$foo = file("../error_log.txt");

 

The '..' means "go to the parent directory."  Since index.php is in wwwroot, the parent directory is mmmvomit.  '../error_log.txt' then translates to '/mmmvomit/error_log.txt'.

 

If I want to get at one of the files in the img folder from within index.php, I would do something like this.

 

<img src="../img/lolcat.gif">

 

The '..' translates to the parent directory of wwwroot, which is mmmvomit.  From there it looks in the img folder, then retrieves lolcat.gif.

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.