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

  • Home
  • SEARCH
  • 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 8210081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:57:05+00:00 2026-06-07T09:57:05+00:00

Error Handling with files in PHP $path = ‘/home/test/files/test.csv’; fopen($path, ‘w’) Here I want

  • 0

Error Handling with files in PHP

$path = '/home/test/files/test.csv';
fopen($path, 'w')

Here I want add an error handling by throwing exceptions, on ‘No file or directory is found’ and ‘No permission to create a file’.

I am using Zend Framework.

By using fopen with write mode, I can create a file. But how to handle it when corresponding folder is not there?
i.e if files folder is not present in root structure.

How to throw an exception when no permission is permitted for creating a file?

  • 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-07T09:57:07+00:00Added an answer on June 7, 2026 at 9:57 am

    Something like this should get you started.

    function createFile($filePath)
    {
      $basePath = dirname($filePath);
      if (!is_dir($basePath)) {
        throw new Exception($basePath.' is an existing directory');
      }
      if (!is_writeable($filePath) {
        throw new Exception('can not write file to '.$filePath);
      }
      touch($filePath);
    }
    

    Then to call

    try {
      createFile('path/to/file.csv');
    } catch(Exception $e) {
      echo $e->getMessage();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a custom error handling / reporting function for PHP file upload
I want to make a general error handling package that should be called from
I am running nginx with PHP-FPM. My nginx configuration for handling php files looks
I have some idea with error handling in PHP - way to immediately get
I'm trying to set up custom error handling, so I setup an ErrorController.php file
I was reading about error handling in SQL Server in this article , and
Thanks to reading about error handling on StackOverflow , I discovered Mz-Tools. However, I
I'm still entangled in error handling problems. After having read and tried lots of
What are some good patterns for error handling in VBA? In particular, what should
I actually have two questions regarding exception/error handling in the iPhone app that I

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.