Solved

Problem implementing my File_Upload Class - 500 points

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

22 Experts available now in Live!

Get 1:1 Help Now