Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem implementing my File_Upload Class - 500 points

Posted on 2006-10-29
4
Medium Priority
?
154 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

670 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