Creating directories... : Newbie Question

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Creating directories... : Newbie Question

    Hey all I have this is a script:

    <?php


    $city = $_GET['city'];
    $state = $_GET['state'];

    if($file_name !="")
    {
    copy ("$file", "/home/guestdir/www/olcg/WPA/$state/$city/$file_name")
    or die("Could not copy file");
    }
    else { die("No file specified"); }
    ?>

    What I'd like to do:

    1. I have the ability to upload graphics into a directory.
    2. If directory isn't available create that directory and upload the
    graphics to that directory.
    2. the ability to save the file path to sql


    Any direction would be greatly appreciated.

    phatnugs420@comcast.net Guest

  2. Similar Questions and Discussions

    1. Creating datasource with mysql- newbie question
      Hi all, I have been using a program to connect to mysql database on my shared hosting. I am now setting up a site in dreamweaver and a datasource...
    2. Creating Virtual Directories
      I'm building an application that will host many subdomains under one domain. Each subdomain will be created on the fly by a user for demo purposes....
    3. creating directories; moving .flv files
      hello; I would like to: 1) create a directoryAA on the FCS via a .swf button 2) move a BB.flv from it's default directory into directoryAA; 3)...
    4. Creating Function Newbie question
      Hi I have written a small bit of code for my web site that basically is anti hack code. $checking = ($HTTP_GET_VARS); if (ereg ("+",...
    5. newbie question: creating a new record in a related file
      somaBoyMX wrote: You can do it with a Portal in the Contacts file. First, the relationship from the Contacts file as Master to the related...
  3. #2

    Default Re: Creating directories... : Newbie Question

    [email]phatnugs420@comcast.net[/email] wrote:
    > Hey all I have this is a script:
    >
    > <?php
    >
    >
    > $city = $_GET['city'];
    > $state = $_GET['state'];
    >
    > if($file_name !="")
    > {
    > copy ("$file", "/home/guestdir/www/olcg/WPA/$state/$city/$file_name")
    > or die("Could not copy file");
    > }
    > else { die("No file specified"); }
    > ?>
    >
    > What I'd like to do:
    >
    > 1. I have the ability to upload graphics into a directory.
    > 2. If directory isn't available create that directory and upload the
    > graphics to that directory.
    > 2. the ability to save the file path to sql
    >
    > Any direction would be greatly appreciated.
    For a start, it's pretty dangerous to let a form input just create
    directories willy-nilly, but the warning aside...

    You would need to use is_dir() to check the state and city directories exist
    and create them where appropriate.

    The directories need to be world-writeable so the web server is able to
    write to them (ie your /home/guestdir/www/olcg/WPA directory needs to be
    world-writeable); this in itself is another security risk, as it means
    anyone else on the server could potentially write to these directories as
    well.

    $root = "/home/guestdir/www/olcg/WPA";
    if(!is_dir("$root/$state")) {
    mkdir("$root/$state");
    }
    if(!is_dir("$root/$state/$city")) {
    mkdir("$root/$state/$city");
    }

    Getting the file from the form is covered nicely in the PHP manual at
    [url]http://www.php.net/manual/en/features.file-upload.php[/url]

    Just remember to put enctype="multipart/form-data" in your form tag (this is
    probably one of the most common mistakes when it comes to file uploads).

    Saving the data to the database is a simple SQL query, but the functions
    used depend on the database server you are using, or whether you're using
    something like the PEAR library or the ADODB one.

    --
    Chris Hope - The Electric Toolbox - [url]http://www.electrictoolbox.com/[/url]
    Chris Hope Guest

  4. #3

    Default Re: Creating directories... : Newbie Question

    Not sure where you getting the files..

    so write a file upload routine php.net example here
    [url]http://us2.php.net/features.file-upload[/url]
    then test to see if directory exist if not make directory and move file to
    that directory.

    might not be the best code but you can get the idea

    <?php
    // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used
    instead
    // of $_FILES.

    $city = $_REQUEST['city'];
    $state = $_REQUEST['state'];

    $base_dir = "/home/guestdir/www/olcg/WPA/";

    // Test to see if directory exists or not
    if(!is_dir("$base_dir/$state/$city"){
    mkdir("$base_dir/$state/$city", 0700);
    }

    $uploaddir = "$base_dir/$state/$city";

    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
    } else {
    echo "Possible file upload attack!\n";
    }

    ?>


    <phatnugs420@comcast.net> wrote in message
    news:BD9097B9.948F%phatnugs420@comcast.net...
    > Hey all I have this is a script:
    >
    > <?php
    >
    >
    > $city = $_GET['city'];
    > $state = $_GET['state'];
    >
    > if($file_name !="")
    > {
    > copy ("$file", "/home/guestdir/www/olcg/WPA/$state/$city/$file_name")
    > or die("Could not copy file");
    > }
    > else { die("No file specified"); }
    > ?>
    >
    > What I'd like to do:
    >
    > 1. I have the ability to upload graphics into a directory.
    > 2. If directory isn't available create that directory and upload the
    > graphics to that directory.
    > 2. the ability to save the file path to sql
    >
    >
    > Any direction would be greatly appreciated.
    >
    >

    Ninjaboy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139