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 1007951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:41:44+00:00 2026-05-16T08:41:44+00:00

http://en.wikipedia.org/wiki/Special_Folders I am having a problem with accessing a special folder in a fopen

  • 0

http://en.wikipedia.org/wiki/Special_Folders

I am having a problem with accessing a special folder in a fopen stream in php.

Example

$fp = fopen("%USERPROFILE%/Desktop/text.txt", 'wb');
fwrite($fp, $data);
fclose($fp);

I try this with sysinternals process monitor running to try and see what is actually happening and it looks something like this.

C:/xampp/htdocs/test/%USERPROFILE%/Desktop/text.txt  PATH NOT FOUND

Well apparently two thing are going wrong, PHP is treating the path as a relative path and the special folder is not being evaluated.

  • 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-05-16T08:41:45+00:00Added an answer on May 16, 2026 at 8:41 am
    $fp = fopen("{$_ENV['USERPROFILE']}\\Desktop\\text.txt", 'wb');
    

    See $_ENV on the manual and also getenv().

    As Johannes Rössel said, this will only work in limited circumstances. You can use this internal function instead:

    #include<Shlobj.h>
    
    PHP_FUNCTION(win_get_desktop_folder)
    {
        char szPath[MAX_PATH];
    
        if (zend_parse_parameters_none() == FAILURE)
            RETURN_NULL();
    
        if (SUCCEEDED(SHGetSpecialFolderPathA(NULL, szPath,
            CSIDL_DESKTOP, FALSE))) {
            RETURN_STRING(szPath, 1);
        } else {
            RETURN_FALSE;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to http://en.wikipedia.org/wiki/Producer-consumer_problem I want to simulate P/C problem using semaphore. I am getting
http://en.wikipedia.org/wiki/All_nearest_smaller_values . This is the site of the problem and here is my code,
I wish to use Wikipedia api to extract the result of this page: http://en.wikipedia.org/wiki/Special:PrefixIndex
I have the following URL: http://en.wikipedia.org/wiki/Special:Export/Birkdale,_Queensland I want to get the following out of
While reading http://en.wikipedia.org/wiki/C_preprocessor#Multiple_evaluation_of_side_effects , I came across this example: \#define max(a,b) \ ({ typeof
Using the coffee decorator example shown on Wikipedia ( http://en.wikipedia.org/wiki/Decorator_pattern ) how would it
http://en.wikipedia.org/wiki/CMAC http://www.rfc-archive.org/getrfc.php?rfc=4493 There are two keys K1 and K2. Are there any other reasons,
Take this for example: http://en.wikipedia.org/wiki/United_States_Bill_of_Rights Under the Amendments section, I want to get what
I'm using PeerTracker http://en.wikipedia.org/wiki/PeerTracker to track torrent hashes. I have a simple HTML page
I have read the explanation in http://en.wikipedia.org/wiki/PageRank and i understand that the page rank

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.