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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:22:13+00:00 2026-06-10T06:22:13+00:00

I know you can create a temporary file with tmpfile and than write to

  • 0

I know you can create a temporary file with tmpfile and than write to it, and close it when it is not needed anymore. But the problem I have is that I need the absolute path to the file like this:

"/var/www/html/lolo/myfile.xml"

Can I somehow get the path, even with some other function or trick?

EDIT:

I want to be able to download the file from the database, but without

$fh = fopen("/var/www/html/myfile.xml", 'w') or die("no no");
fwrite($fh, $fileData);
fclose($fh); 

because if I do it like this, there is a chance of overlapping, if more people try to download the same file at exactly the same time. Or am I wrong?

EDIT2:

Maybe I can just generate unique(uniqID) filenames like that, and than delete them. Or can this be too consuming for the server if many people are downloading?

  • 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-10T06:22:15+00:00Added an answer on June 10, 2026 at 6:22 am

    For newer (not very new lol) versions of PHP (requires php 5.2.1 or higher) @whik’s answer is better suited:

    <?php 
    // Create a temp file in the temporary 
    // files directory using sys_get_temp_dir()
    $temp_file = tempnam(sys_get_temp_dir(), 'MyFileName');
    echo $temp_file;
    ?>
    

    The above example will output something similar to: /var/tmp/MyFileNameX322.tmp

    old answer

    Just in case someone encounters exactly the same problem. I ended up doing

    $fh = fopen($filepath, 'w') or die("Can't open file $name for writing temporary stuff.");
    fwrite($fh, $fileData);
    fclose($fh);
    

    and

    unlink($filepath); 
    

    at the end when file is not needed anymore.

    Before that, I generated filename like that:

    $r = rand();        
    $filepath = "/var/www/html/someDirectory/$name.$r.xml";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can create a List<T> from IEnumerable<T> by doing myEnumerableCollection.ToList() , but
I know I can create a plot with line and dots using the type
Does anyone know how I can create a Completely transparent image or given am
I would like to know how can I create a regexp to match the
I want to know if PHPExcel can: Create Excel spreadsheets with embeded image. The
I want to know if I can create a WebBrowser through code in Vb.NET,
I'm using python 3.1.1. I know that I can create byte objects using the
I know that horizontal partitioning...you can create many tables. How can you do this
Does anyone know how I can Dynamically create an installation package that installs files
I know with swift directly you can create a Recipient_List and do ->addBcc() .

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.