Mencarta Posted April 8, 2010 Share Posted April 8, 2010 I get the error: Warning: filesize() [function.filesize]: stat failed for Fever 1.0.png in C:\apache\server\projects\upload.php on line 38 When I submit an image through this code.upload.php <?php $links = 5242880; $pics = 2060451840; $pptx = 2060451840; if (isset($_POST["type"])) { if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) { if ($_POST["type"] == "pptx" && $_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation") { $tmp = $_FILES["file"]["tmp_name"]; $name = $_FILES["file"]["name"]; $dir = $_POST["type"]."/".$name; if ($handle = opendir("pptx")) { $size = 0; while (false !== ($file = readdir($handle))) { $size += filesize($file); } } if ($size >= $pptx) { $files = 0; while (false !== ($file = readdir($handle1))) { if ($files == 3) break; unlink($file); } } move_uploaded_file($tmp,$dir); if (file_exists($dir)) { header("Location: uploaded.php?file=".$name); } else { header("Location: error.php?file=".$name); } } if ($_POST["type"] == "scrapbooks" || $_POST["type"] == "gallery" && $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/gif") { if ($handle = opendir("scrapbooks")) { $size = 0; while (false !== ($file = readdir($handle))) { $size += filesize($file); } } if ($handle1 = opendir("gallery")) { $size1 = 0; while (false !== ($file = readdir($handle1))) { $size1 += filesize($file); } } if ($size >= $pics || $size1 >= $pics) { if ($size >= $pics) { $files = 0; while (false !== ($file = readdir($handle))) { if ($files == 3) break; unlink($file); } } if ($size1 >= $pics) { $files = 0; while (false !== ($file = readdir($handle1))) { if ($files == 3) break; unlink($file); } } } $tmp = $_FILES["file"]["tmp_name"]; $name = $_FILES["file"]["name"]; $dir = $_POST["type"]."/".$name; move_uploaded_file($tmp,$dir); if (file_exists($dir)) { header("Location: uploaded.php?file=".$name); } else { header("Location: error.php?file=".$name); } } } if ($_POST["type"] == "links") { $text = $_POST["link"]; if (filesize("links.txt") < $links) { $file = fopen("links.txt","a"); fwrite($file,"\r\n".$text); fclose($file); header("Location: uploaded.php?link=".$text); } else { $links = array(); $file = fopen("links.txt"); while (true) { $line = fgets($file); if ($line == null) break; $links[] = $line; } for ($i = 0;$i < 5;$i++) { unset($links[$i]); } $file = fopen("links.txt","w"); foreach ($links as $link) { fwrite($file,$link); } fwrite($file,"\r\n".$text); fclose($file); header("Location: uploaded.php?link=".$text); } } }?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html> <head> <title>Fever 1793 - Upload</title> <link rel="stylesheet" type="text/css" href="fever.css" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(function() { $("div.file").slideUp("fast"); $("div.link").slideUp("fast"); $("input.file").click(function() { $("div.link").slideUp("slow"); $("div.file").slideDown("slow"); }); $("input.link").click(function() { $("div.file").slideUp("slow"); $("div.link").slideDown("slow"); }); }) </script> </head> <body> <div id="header"> <h1>Fever 1793</h1> </div> <div id="page"> <form enctype="multipart/form-data" action="upload.php" method="post"> <b>Select the item you would like to upload</b> <br /> Upload: <input class="link" type="radio" name="type" value="links"> <b>Link</b> | <input class="file" type="radio" name="type" value="pptx"> <b>Powerpoint</b> | <input class="file" type="radio" name="type" value="scrapbooks"> <b>Scrapbook</b> | <input class="file" type="radio" name="type" value="gallery"> <b>Gallery</b> <br /> <br /> <br /> <div class="file"> <b>Choose the file</b> <br /> File: <input type="file" name="file"> <br /> <input type="submit" value="Upload" /> </div> <div class="link"> <b>Type the link</b> <br /> Link: <input name="link" type="text" maxlength="200" /> <br /> <input type="submit" value="Upload" /> </div> </form> <br /> <br /> <a style="color:rgb(0,0,0);" href="fever.php" title="Home">Home</a> </div> </body></html> What should I do? Link to comment Share on other sites More sharing options...
real_illusions Posted April 8, 2010 Share Posted April 8, 2010 lines 36 to 38 are these:$size = 0;while (false !== ($file = readdir($handle))) {$size += filesize($file);Surely the $size should be larger than 0? However, I'm sure theres a php function that gets the size of the file (filemsize or something maybe?) so maybe look into that if you haven't already.Whenever theres an error in php, it tells you what line the error occured on. So look back to that line and the lines before to see where the problem could of occured. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2010 Share Posted April 8, 2010 It's probably a path issue. $file is just a filename from a directory you've opened, not a complete path. The filesize function needs a complete path in order for it to work. Link to comment Share on other sites More sharing options...
Mencarta Posted April 8, 2010 Author Share Posted April 8, 2010 Doesn't work. I modified to the code to:upload.php <?php $links = 5242880; $pics = 2060451840; $pptx = 2060451840; $path = "http://localhost/projects"; if (isset($_POST["type"])) { if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) { if ($_POST["type"] == "pptx" && $_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation") { $tmp = $_FILES["file"]["tmp_name"]; $name = $_FILES["file"]["name"]; $dir = $_POST["type"]."/".$name; if ($handle = opendir("pptx")) { $size = 0; while (false !== ($file = readdir($handle))) { $size += filesize($path."/gallery/".$file); } } if ($size >= $pptx) { $files = 0; while (false !== ($file = readdir($handle1))) { if ($files == 3) break; unlink($file); } } move_uploaded_file($tmp,$dir); if (file_exists($dir)) { header("Location: uploaded.php?file=".$name); } else { header("Location: error.php?file=".$name); } } if ($_POST["type"] == "scrapbooks" || $_POST["type"] == "gallery" && $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/gif") { if ($handle = opendir("scrapbooks")) { $size = 0; while (false !== ($file = readdir($handle))) { $size += filesize($path."/gallery/".$file); } } if ($handle1 = opendir("gallery")) { $size1 = 0; while (false !== ($file = readdir($handle1))) { $size1 += filesize($path."/gallery/".$file); } } if ($size >= $pics || $size1 >= $pics) { if ($size >= $pics) { $files = 0; while (false !== ($file = readdir($handle))) { if ($files == 3) break; unlink($file); } } if ($size1 >= $pics) { $files = 0; while (false !== ($file = readdir($handle1))) { if ($files == 3) break; unlink($file); } } } $tmp = $_FILES["file"]["tmp_name"]; $name = $_FILES["file"]["name"]; $dir = $_POST["type"]."/".$name; move_uploaded_file($tmp,$dir); if (file_exists($dir)) { header("Location: uploaded.php?file=".$name); } else { header("Location: error.php?file=".$name); } } } if ($_POST["type"] == "links") { $text = $_POST["link"]; if (filesize("links.txt") < $links) { $file = fopen("links.txt","a"); fwrite($file,"\r\n".$text); fclose($file); header("Location: uploaded.php?link=".$text); } else { $links = array(); $file = fopen("links.txt"); while (true) { $line = fgets($file); if ($line == null) break; $links[] = $line; } for ($i = 0;$i < 5;$i++) { unset($links[$i]); } $file = fopen("links.txt","w"); foreach ($links as $link) { fwrite($file,$link); } fwrite($file,"\r\n".$text); fclose($file); header("Location: uploaded.php?link=".$text); } } }?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html> <head> <title>Fever 1793 - Upload</title> <link rel="stylesheet" type="text/css" href="fever.css" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(function() { $("div.file").slideUp("fast"); $("div.link").slideUp("fast"); $("input.file").click(function() { $("div.link").slideUp("slow"); $("div.file").slideDown("slow"); }); $("input.link").click(function() { $("div.file").slideUp("slow"); $("div.link").slideDown("slow"); }); }) </script> </head> <body> <div id="header"> <h1>Fever 1793</h1> </div> <div id="page"> <form enctype="multipart/form-data" action="upload.php" method="post"> <b>Select the item you would like to upload</b> <br /> Upload: <input class="link" type="radio" name="type" value="links"> <b>Link</b> | <input class="file" type="radio" name="type" value="pptx"> <b>Powerpoint</b> | <input class="file" type="radio" name="type" value="scrapbooks"> <b>Scrapbook</b> | <input class="file" type="radio" name="type" value="gallery"> <b>Gallery</b> <br /> <br /> <br /> <div class="file"> <b>Choose the file</b> <br /> File: <input type="file" name="file"> <br /> <input type="submit" value="Upload" /> </div> <div class="link"> <b>Type the link</b> <br /> Link: <input name="link" type="text" maxlength="200" /> <br /> <input type="submit" value="Upload" /> </div> </form> <br /> <br /> <a style="color:rgb(0,0,0);" href="fever.php" title="Home">Home</a> </div> </body></html> And got the error: Warning: filesize() [function.filesize]: stat failed for http://localhost/projects/gallery/burntpaper.png in C:\apache\server\projects\upload.php on line 45 Link to comment Share on other sites More sharing options...
justsomeguy Posted April 8, 2010 Share Posted April 8, 2010 Use the local path, not the URL. The local path should start with a drive letter. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.