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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:31:14+00:00 2026-05-31T02:31:14+00:00

My php script is supposed to simply take a filename and within a specific

  • 0

My php script is supposed to simply take a filename and within a specific directory outputs the filename’s contents. The issue is that it does that BUT it apparently once again calls the case resulting in throwing errors, I have tried to replace switch with if/else but still it recalls itself(The code related to case:”1″). Here are the error:

    Warning: fopen(C:/xampp/htdocs/phptut/practice/) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\phptut\practice\fileuploadread.php on line 8

    Warning: fread() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\phptut\practice\fileuploadread.php on line 9

    Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\phptut\practice\fileuploadread.php on line 10

And This is the code:

    switch($_GET['id']){
        case"1":

            {   //here $file gets the pathtothefile + filename
                $file="C:/xampp/htdocs/phptut/practice/" . $_POST["element"];
                $fh=fopen($file,"r");
                $contents=fread($fh,filesize($file));
                fclose($fh);
                   //It does output the $contents at this point
                echo $contents;

            }
            break;
        default:{

            echo"
                <html>
                        <head>
                            <style type='text/css'>
                                fieldset{
                                    background-color:lightblue;
                                    border-color:blue;
                                    width:50%;
                                    margin-left:auto;
                                    margin-right:auto;
                                    margin-top:200px;

                                }
                                legend{
                                    color:blue;

                                }
                            </style>
                        </head>
                        <body>
                            <fieldset>
                                <legend> Upload Your CV </legend>
                                <form method='POST' name='form' action='fileuploadread.php?id=1'>
                                    <input type='input' name='element' size='20' /><br/>
                                    <input type='submit' value='submit...'/>
                                </form>
                            </fieldset> 
                        </body>
                    </html>
                    ";
    }       }
    ?>
  • 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-31T02:31:15+00:00Added an answer on May 31, 2026 at 2:31 am

    I’m not sure what real problem is here, but you should check file pointer is good before using it in fread() and fclose() calls

    $fh=fopen($file,"r");
    if ($fh) {
       $contents=fread($fh,filesize($file));
       fclose($fh);
    }
    

    If there is a chance the file does not exist, then check first and deal with it.

    if (file_exists($file)) {
       // do something with file
    } else {
       // do something else
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that's supposed to take in a URL and search
I have a simple PHP script that is supposed to redirect to another document
I have created a PHP-script to update a web server that is live inside
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via
I have a PHP script that initialises an image gallery. It loops through all
I have a PHP script that can encode a PNG image to a Base64
I have a very simple php ldap script that is only failing when running
I have a PHP script that needs to run from command line. One of
Situation: A user submits a url and my php script adds that url to

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.