Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:21:55+00:00 2026-06-04T20:21:55+00:00

I seem to be having an issue with using variables to create directories via

  • 0

I seem to be having an issue with using variables to create directories via the mkdir() function. The variable is being parsed from the URL. See my coding below:

$pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$pageURL;
$url = $pageURL;
$parse = parse_url($url);
$dirID = $parse['query'];

I’m using define() to define the folder path since the path is used several times throughout the code:

 define("DESTINATION_FOLDER", "mydir/".$dirID."/");

And here is the if statement telling it to create the directory if it doesn’t exist:

if (!@file_exists(DESTINATION_FOLDER)) {      
    mkdir(DESTINATION_FOLDER);
}

Sounds pretty straightforward but for some reason the variable $dirID does not get read, and the file instead uploads to the mydir directory. What’s really odd, is that if I hardcode the variable to something like $dirID = “28”, it works and the file gets uploaded like mydir/28/file.jpg. I have used this method to pass variables many times before, but never to pass a variable to be used in the mkdir function. Does anyone know what might be going on?

Thank you in advance for any and all help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:21:57+00:00Added an answer on June 4, 2026 at 8:21 pm

    This is all in the comments above, but I’ll spell it out:

    The query part is never actually passed to URL, and therefore not passed into “parse”.

    I’ll paraphrase your code:

    1. Construct URL using protocal (http/https) and server name and URL. (Note – you’re not appending the query at this point)
    2. Parse the url (which does not include the query)
    3. Get the query from the parse (which still isn’t there)

    $_SERVER[‘QUERY_STRING’] is the bit you’re looking for – you can either add to the URL and then parse, or just use it directly

    $dirID = $_SERVER['QUERY_STRING'];
    

    But why you’d use that to create the directory is a bit (A LOT) dangerous as it’ll invariably contain invalid parameters. As suggested in the comments, you probably mean to get a particular value for a query string parameter? Or is it the actual string. You can get these from:

    // For ?DirectoryName
    $aKeys = array_keys($_GET)
    $directoryName = isset($aKeys[0]) ? $aKeys[0] : '';
    

    or

    // For ?ParamName=DirectoryName
    $directoryName = $_GET['ParamName']
    

    I then also suggest you use a preg_match to validate the directory name meets an acceptable format and to avoid crap being created!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to be having an issue, the application we're using uses a Ninject
I am having an issue with my function. I can't seem to figure out
I am having an issue that I can't seem to figure out. Hopefully somebody
I am having a strange issue that I can't seem to resolve. Here is
Okay, I seem to be having a problem. I'm trying to create a twicker
having an issue using a NSMutableArray; In my implementation file applicationDidFinishLaunching method I have
I'm having an issue querying Solr using the following field type: <fieldType name=text_ci class=solr.TextField
I'm having an issue accessing raw request information from PHP when accessing a script
I'm having an issue when calling 32 bit Delphi DLL files from a C#
Seem to be having an issue with the tablesorter plugin and excluding columns for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.