ncepeda Posted August 5, 2008 Share Posted August 5, 2008 I have a code that looks like this. The problem is it will not upload anything over a certain size... is there anything in this code that is restricting it. Or do you think it in in my php.ini file? include "inc/application_top.php"; require "inc/functions/pagination.php"; //redirect to the project selection page if no project is selected if (!$project_id) { header("Location: project_select.php"); } //save the file to pc //must be done at page top for headers to work if ($save_file) { @ob_end_clean(); @ini_set("zlib.output_compression", "Off"); header("Pragma: public"); header("Last-Modified: ".gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: pre-check=0, post-check=0, max-age=0"); header("Content-Transfer-Encoding: none"); header("Content-type: text/plain"); header("Content-Disposition: attachment; filename=".$filename.""); @readfile($upload_dir . $filename); exit; } //delete file if ($delete_file) { unlink($upload_dir . $filename); $message = "<p class=\"success\">".TEXT_FILE_DELETED."</p>"; } //upload the files if ($upload_file) { //************************************************************************ //CHECK FOR DIRECTORIES / CREATE THEM ************************************ //************************************************************************ //check for clients personal folder if (is_dir($client_dir)) { $client_dir_exists = "true"; } else { $client_dir_exists = "false"; } //check for projects folder if (is_dir($project_dir)) { $project_dir_exists = "true"; } else { $project_dir_exists = "false"; } //check for uploads folder if (is_dir($upload_dir)) { $upload_dir_exists = "true"; } else { $upload_dir_exists = "false"; } //if client_dir directory is missing if ($client_dir_exists == "false") { //create the clients folder mkdir($client_dir); } //if project directory is missing if ($project_dir_exists == "false") { //create the project folder mkdir($project_dir); } //if upload directory is missing if ($upload_dir_exists == "false") { //create the upload folder mkdir($upload_dir); } //************************************************************************ //UPLOAD THE FILES ******************************************************* //************************************************************************ while(list($key,$value) = each($_FILES[files][name])) { // check if any blank field is entered if(!empty($value)){ // filename stores the value $filename = $value; //replace all spaces with underscores to avoid errors $filename = str_replace (" ", "_", $filename) ; // upload directory path is set $add = $upload_dir . $filename; // validate the file type //these file types are not allowed if ( ($_FILES[files][type][$key] == "application/x-php") or ($_FILES[files][type][$key] == "application/exe") or ($_FILES[files][type][$key] == "application/x-exe") ) { $uploaded_filetype = $_FILES[files][type][$key]; //file type is not allowed $filetype = "false"; $message = "<p class=\"error\">".TEXT_FILETYPE_BANNED."</p>"; //file type is ok } else { $filetype = "true"; } //display the file type //echo $_FILES[files][type][$key]; // validate the file size if ($_FILES[files][size][$key] > CONFIG_MAX_FILESIZE) { //define uploaded file size $upload_file_size = number_format(($_FILES[files][size][$key] * 0.0009765625), 2, '.', ''); //define max file size $max_file_size = number_format((CONFIG_MAX_FILESIZE), 2, '.', ''); //file too big $filesize = "false"; $message = "<p class=\"error\">".TEXT_FILE_TOO_BIG."</p>"; //file size is ok } else { $filesize = "true"; } //display the file size //echo $_FILES[size][type][$key]; if (($filetype == "true") && ($filesize == "true")) { // upload the file to the server copy($_FILES[files][tmp_name][$key], $add); $message = "<p class=\"success\">".TEXT_FILE_SUCCESSFUL."</p>"; // set permission to the file. chmod("$add",0777); //the file is not uploaded } else { $message = "<p class=\"error\" >".TEXT_FILE_FAILED."</p>"; } } } } ?> <?php echo CONFIG_DOCTYPE . "\n" ?> <html <?php echo HTML_PARAMS; ?>> <head> <title><?php echo CONFIG_STORE_NAME ?><?php echo CONFIG_TITLE_SEPERATOR ?><?php echo TEXT_TITLE_FILE_MGR;?></title> <link rel="stylesheet" href="<?php echo CONFIG_TEMPLATE_DIR ?>css/style.css" type="text/css" /> <link rel="stylesheet" media="print" href="<?php echo CONFIG_TEMPLATE_DIR ?>css/print.css" type="text/css" /> <script type="text/javascript" src="<?php echo CONFIG_STORE_URL . CONFIG_STORE_PATH ?>inc/js/formvalidation.js"></script> <!--[if IE]> <link href="<?php echo CONFIG_TEMPLATE_DIR ?>css/ie.css" rel="stylesheet" type="text/css" /> <![endif]--> <link rel="shortcut icon" href="favicon.ico" /> </head> <body> <?php require CONFIG_TEMPLATE_DIR . "header.php"; ?> <h1><?php echo TEXT_TITLE_FILE_MGR;?></h1> <?php // display error messages that occurred at the top of the page if (isset($message)) { echo $message; } ?> <?php //a project has been chosen if ($project_id) { //get the project name $query = "SELECT DISTINCT epay_projects.name FROM epay_projects JOIN epay_invoices on epay_invoices.project_id = epay_projects.project_id WHERE clientid = '$client_id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $project_name = $row["name"]; ?> <?php if ($user_type == TEXT_USERTYPE_USER) { ?> <p><input class="css_button" type="button" value="<?php echo TEXT_BACK;?>" title="<?php echo TEXT_BACK;?>" onClick="window.location.href='<?php echo CONFIG_STORE_URL . CONFIG_STORE_PATH; ?>project_select.php?clientid=<?php echo $client_id;?>&project_id=<?php echo $project_id;?>'" /></p> <?php } else { ?> <p><input class="css_button" type="button" value="<?php echo TEXT_BACK;?>" title="<?php echo TEXT_BACK;?>" onClick="window.location.href='<?php echo CONFIG_STORE_URL . CONFIG_STORE_PATH; ?>project_select_admin.php?clientid=<?php echo $client_id;?>&project_id=<?php echo $project_id;?>'" /></p> <?php } ?> <?php } ?> <form action="<?php echo $basename;?>" enctype="multipart/form-data" method="post"> <input type="hidden" name="project_id" value="<?php echo $project_id; ?>" /> <input type="hidden" name="clientid" value="<?php echo $clientid; ?>" /> <?php for($i=1; $i <= CONFIG_MAX_UPLOADS; $i++) { ?> <input type="file" name="files[]" /><br /> <?php } ;?> <p> <input type="submit" class="css_button" name="upload_file" value="<?php echo TEXT_UPLOAD;?>" /> </p> </form> <?php if (is_dir(CONFIG_STORE_ABSOLUTE_URL . $upload_dir)) { // open this directory $myDirectory = opendir(CONFIG_STORE_ABSOLUTE_URL . $upload_dir); // get each entry while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } // close directory closedir($myDirectory); // count elements in array $indexCount = count($dirArray); if ($indexCount >= 3) { // sort 'em sort($dirArray); // print 'em echo "<p></p>"; echo "<table class=\"invoice-list\">"; echo "<tr>"; echo "<th>".TEXT_FILENAME."</th>"; echo "<th>".TEXT_FILETYPE."</th>"; echo "<th>".TEXT_FILESIZE."</th>"; echo "<th></th>"; echo "<th></th>"; echo "</tr>"; // loop through the array of files and print them all $num_classes = 2; $i = 0; for($index=0; $index < $indexCount; $index++) { if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files //calculate bytes into kb $file_size = number_format((filesize($upload_dir . $dirArray[$index]) * 0.0009765625), 2, '.', ''); //get the file extension $file_type = substr($dirArray[$index], strrpos($dirArray[$index], '.') + 1); echo "<tr class=\"row_".$i++%$num_classes."\">"; echo "<td>".$dirArray[$index]."</td>"; echo "<td>".$file_type."</td>"; echo "<td>".$file_size." Kb</td>"; echo "<td><a href=\"".$basename."?project_id=".$project_id."&clientid=".$clientid."&delete_file=yes&filename=".$dirArray[$index]."\" onclick=\"return confirm('".TEXT_DELETE_FILE."?')\" title=\"".TEXT_DELETE_FILE."\"><img src=\"".CONFIG_ICON_DIR."delete.png\" alt=\"".TEXT_DELETE_FILE."\" title=\"".TEXT_DELETE_FILE."\" /></a></td>"; echo "<td><a href=\"".$basename."?project_id=".$project_id."&clientid=".$clientid."&save_file=yes&filename=".$dirArray[$index]."\" title=\"".TEXT_SAVE_FILE."\"><img src=\"".CONFIG_ICON_DIR."save.png\" alt=\"".TEXT_SAVE_FILE."\" title=\"".TEXT_SAVE_FILE."\" /></a></td>"; echo "</tr>\n"; } } echo "</table>\n"; } } ?> <?php require CONFIG_TEMPLATE_DIR . "footer.php"; ?> </body> </html> EDITED BY WILDTEEN88: Please wrap code within code tags ( ) Link to comment https://forums.phpfreaks.com/topic/118336-help-with-file-uploads/ Share on other sites More sharing options...
realjumper Posted August 5, 2008 Share Posted August 5, 2008 What size does "certain size" mean? I think the default in php.ini is 2mb Link to comment https://forums.phpfreaks.com/topic/118336-help-with-file-uploads/#findComment-609011 Share on other sites More sharing options...
DarkPrince2005 Posted August 6, 2008 Share Posted August 6, 2008 try setting the max_post_size in your code. it might be the php.ini limiting your upload. I had the same problem, but since i've added this part of code i don't seem to have it anymore ini_set('post_max_size' , '100M'); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/118336-help-with-file-uploads/#findComment-609086 Share on other sites More sharing options...
TempleDMDKrazd Posted August 6, 2008 Share Posted August 6, 2008 What size does "certain size" mean? I think the default in php.ini is 2mb you are correct the default size is 2 meg... Link to comment https://forums.phpfreaks.com/topic/118336-help-with-file-uploads/#findComment-609147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.