Solved

Problem implementing my File_Upload Class - 500 points

Posted on 2006-10-29
4
147 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now