SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    determining temp directory for created files

    OK, I know I posted this before...but for some reason, I'm not seeing it and so maybe I'm just losing my mind???

    The question is this: is there a way to programmatically determine the server's default temp directory for files that have been created - not uploaded? Here's the code for what I'm doing...

    $today = date(time());
    $filepath = "/_Inc/admissions/csvs/";
    $newfile = $today . ".csv";

    $sql = " SELECT a.applicant_id, a.date_added, q.field_name, q. field_type, r.response_value, ar.applicant_response_text";
    $sql = $sql . " INTO OUTFILE '" . $newfile . "' FIELDS TERMINATED BY ', ' OPTIONALLY ENCLOSED BY '''' LINES TERMINATED BY ';\n'";
    $sql = $sql . " FROM applicant AS a, question AS q, response AS r, applicant_response AS ar";
    $sql = $sql . " WHERE a.applicant_id = ar.applicant_id AND q.question_id = ar.question_id AND r.response_id = ar.response_id";
    $results = mysql_query($sql) or die("File creation not successfulbr>" . $sql . "<br>" . mysql_error());
    if ($results) {
    print("File $newfile has been created.");
    $move_successful = copy($newfile,$filepath);
    if ($move_successful) {
    print("<a href=\"#\" onClick=\"window.open('$filepath$newfile','Download');\">Click here to download $newfile.</a><p>\n");
    }
    // end if
    print("<a href=\"/config.php\">Return to configuration screen.</a>\n");
    }
    // end if
    else {
    print("An unknown error has occurred.");
    }
    // end else

    Sorry for the crappy formatting on this size form field...

    Anyway, this version tries to copy the created file to the right directory, but of course it doesn't work because the copy() function can't locate the file. I've tried this several ways: using the $filepath variable as the prefix to the $newfile variable in the SELECT INTO OUTFILE clause (which generates an error of being unable to create/write file - although the directory has rw privileges assigned to everyone for testing), moving the file into the $filepath directory after creating it using the move_uploaded_file() function (generates same problem as the copy() function), and the way you see here.

    I can't set the server's temp directory using upload_tmp_dir because 1) it would affect other developer's scripts on the same machine, 2) this file isn't being uploaded - it's being created!!!

    Is there a distinction between the two? Is there a way to programmatically search the server variables to find the default temp directory?

    I've finally got uploading licked - this should be EASY in comparison, darnit!!!

    Mandi
    Love ya - mean it!

  2. #2
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First off, include PHP code within [#php] ...code... [#/php] without the hashes(#), second try this,
    PHP Code:
    $sql  "SELECT FROM aTable";
    $sql .= "WHERE something = 'condition'"
    the '.=' (concat) will make your code look better.

    For the answer to your main question, just explicitly name the dir to create file...

    PHP Code:
    $today date(time()); 
    $filepath "/_Inc/admissions/csvs/"
    $newfile "path/of/other/temp/dir/" $today ".csv"
    That should do it...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  3. #3
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that doesn't do it - I explained that I'd already tried explicity naming the entire filepath in the INTO OUTFILE clause (which is where that would have to go for it to be properly accessible), which throws a "cannot create/write file" error.

    And thanks for the formatting tips - but as an ASP programmer, it makes more sense for me to keep the syntax structures as similar as possible so as not to confuse myself or the other devs here...

    So any other suggestions?

    Mandi
    Love ya - mean it!


Bookmarks

Posting Permissions

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