Solved

Problem implementing my File_Upload Class - 500 points

Posted on 2006-10-29
4
152 Views
Last Modified: 2008-03-04
I'm getting the following error and I'm not sure why:

Warning: filesize() [function.filesize]: stat failed for C:\WINDOWS\TEMP\php1786.tmp in C:\Documents and Settings\username\My Documents\UploadFiles.php on line 140

Here is the code that the error refers to.  The function is defined within a class.  Can someone tell me if this is a coding problem or a permissions problem?

      // Returns file size in a user friendly, readable format
      function get_file_size() {
            // Define variables to be used by function
            $temp_file_name = trim($this->temp_file_name);
            $kb = 1024;
            $mb = 1024 * $kb;
            $gb = 1024 * $mb;
            $tb = 1024 * $gb;
            
            // Check to see if temp file name is valid, if not, return error.
            // Get the file size in bytes using filesize() function.  Return a readable file size.
            if ($temp_file_name)
            {
<HERE IS LINE 140>            $size = filesize($temp_file_name);
                  if ($size < $kb)
                  {
                        $file_size = "$size Bytes";
                  }
                  elseif ($size < $mb)
                  {
                        $final = round($size/$kb,2);
                        $file_size = "$final KB";
                  }
                  elseif ($size < $gb)
                  {
                        $final = round($size/$mb,2);
                        $file_size = "$final MB";
                  }
                  elseif ($size < $tb)
                  {
                        $final = round($size/$gb,2);
                        $file_size = "$final GB";
                  }
                  else
                  {
                        $final = round($size/$tb,2);
                        $file_size = "$final TB";
                  }
            }
            else
            {
                  $file_size = "ERROR: NO FILE PASSED TO get_file_size()";
            }
            return $file_size;
      }

0
Comment
Question by:dyarosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 17830066
My first hunch would be it is a permission problem.

-r-
0
 

Author Comment

by:dyarosh
ID: 17830109
What permission needs to be set in order for this to work?  The file is able to be created.
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 17830124
The file is created by your webserver, not by php. You don't however need to actually use the filesize call, as the size is part of the $_FILES entry:

$_FILES['your_file_key']['size'] = something;
0
 

Author Comment

by:dyarosh
ID: 17830632
I took your advice and changed the call to use the $_FILES variable.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question