Vraag & Antwoord

Webprogrammeren & scripting

MAX_FILE_SIZE werkt niet?

12 antwoorden
  • Hallo allemaal ik gebruik dit script om bestanden te uploaden maar mijn filesize check die werkt niet iemand een idee wat er fout zit? [code:1:94900eb87e] //check file size in bytes 1024 is 1 mb $maxsize = '1024'; $filesize = filesize($collect['file']); if($filesize>$maxsize) { print'Het bestand dat u probeert te upload is te groot, maximaal: '.$maxsize.'bytes'; $template->display(); die(); } else { [/code:1:94900eb87e] mail.php [code:1:94900eb87e]<?php require("t_engine.php"); require("classes.php"); $template = new jtpl(); $template->readtemplate("templates/mail.tpl"); //als op de verzend knop is gedrukt dan if(isset($_POST['submit'])) { //verzamel ingevoerde gegevens in $collect $collect = array(); $collect['naam'] = $_POST['naam']; $collect['email'] = $_POST['email']; $collect['bericht'] = $_POST['bericht']; $collect['file'] = $_FILES['userfile']['name']; if(!checkmail($collect['email'])) { print'u heeft geen geldig email adres opgegeven'; $template->display(); die(); } else if(!empty($collect['file'])) { //check file size in bytes 1024 is 1 mb $maxsize = '1024'; $filesize = filesize($collect['file']); if($filesize>$maxsize) { print'Het bestand dat u probeert te upload is te groot, maximaal: '.$maxsize.'bytes'; $template->display(); die(); } else { //upload upload($collect['file']); } } else { print'u moet een bestand selecteren'; } /** * verander de emailinstellingen naar je eigen email adres! */ $to = 'mijn email'; $subject = 'Er is een bestand geupload'; $message = 'Naam:'.$collect['naam']."\r\n"; $message.= 'Email van:'.$collect['email']. "\r\n"; $message.= 'Toelichting:'.$collect['bericht']. "\r\n"; $message.= 'File die is ge-upload:'.$collect['file']. "\r\n"; $headers = 'From: mijn email' . "\r\n" . 'Reply-To: mijn email' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); /** * -------------------------------------------------- */ $mail = mail($to, $subject, $message, $headers); //bedankt mail naar aanvrager //$mail = mail($collect['email'], 'Beste' .$collect ['naam'], 'Bedankt voor het uploaden van uw bestand '.$collect['naam'], $headers); if(!$mail) { print'Het versturen van uw bericht is niet gelukt neem contact op met de webmaster of probeer het later nog eens.'; } else { $template->assignvar("NAAM", $collect['naam']); $template->readtemplate("templates/bedankt.tpl"); } } $template->display(); ?>[/code:1:94900eb87e] en de classes.php [code:1:94900eb87e]<?php //classes /** * by vincent de haan */ function upload($file) { $filename = $file; $allow[0] = "jpg"; $allow[1] = "JPG"; $allow[2] = "avi"; $allow[3] = "AVI"; $allow[4] = "mpg"; $allow[5] = "MPG"; $allow[6] = "mov"; $allow[7] = "MOV"; $allow[8] = "wmv"; $allow[9] = "WMV"; // $allow[5] = "exe"; enz. $uploadname = $filename; $extentie = substr($uploadname, -3); for ($i = 0; $i < count($allow); $i++) { if ($extentie == $allow[$i]) { $check='ok'; } } if ($check) { if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { move_uploaded_file($_FILES['userfile']['tmp_name'], "upload/" . $uploadname); //echo "Uw bestand met de naam: $uploadname is geupload."; } else echo'Uw bestand kon niet worden gupload'; } else { echo'Alleen de volgende formaten zijn toegestaan: jpg, mpg, avi, wmv en mov.'; die(); //tussen aanhalings tekens lukte bij mij niet. } } function checkmail($email) { $email_host = explode("@", $email); $email_host = $email_host[1]; $email_resolved = gethostbyname($email_host); if($email_resolved == $email_host) { $valid = FALSE; } if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$email)) { $valid = TRUE; } else { $valid = FALSE; } return $valid; } ?>[/code:1:94900eb87e]
  • Ik heb het niet getest, maar ik denk dat ik de fout zie: [quote:6ea8e9edab]The $_FILES array is where PHP stores all the information about files. There are two elements of this array that we will need to understand for this example. * uploadedfile - uploadedfile is the reference we assigned in our HTML form. We will need this to tell the $_FILES array which file we want to play around with. * $_FILES['uploadedfile']['name'] - name contains the original path of the user uploaded file. * $_FILES['uploadedfile']['tmp_name'] - tmp_name contains the path to the temporary file that resides on the server. The file should exist on the server in a temporary directory with a temporary name.[/quote:6ea8e9edab] [quote:6ea8e9edab]$collect['file'] = $_FILES['userfile']['name'];[/quote:6ea8e9edab] [quote:6ea8e9edab]$maxsize = '1024'; $filesize = filesize($collect['file']); if($filesize>$maxsize)[/quote:6ea8e9edab] Jij gebruikt $_FILES['userfile']['name']. Dat bevat het volledige pad naar het bestand, zoals het op de computer van de gebruiker staat. Op de server staat het bestand in het pad dat in $_FILES['userfile']['tmp_name'] staat. Dus je moet [quote:6ea8e9edab]$collect['file'] = $_FILES['userfile']['name'];[/quote:6ea8e9edab] vervanger door [quote:6ea8e9edab]$collect['file'] = $_FILES['userfile']['tmp_name'];[/quote:6ea8e9edab] en dan zou het moeten werken. Ik heb nog een paar opmerkingen: [quote:6ea8e9edab]//check file size in bytes 1024 is 1 mb[/quote:6ea8e9edab] 1024 bytes is 1 kB, niet 1 MB. [quote:6ea8e9edab]$maxsize = '1024';[/quote:6ea8e9edab] Het maakt niet zoveel uit omdat php alles naar alles can casten, maar omdat $maxsize een getal is kan je de aanhalingstekens beter weglaten. Zoals het er nu staat is het een string. [quote:6ea8e9edab]if($filesize>$maxsize) { print'Het bestand dat u probeert te upload is te groot, maximaal: '.$maxsize.'bytes'; $template->display(); die(); }[/quote:6ea8e9edab] Persoonlijk vind ik het volgende netter [quote:6ea8e9edab]if($filesize>$maxsize) { $template->display(); die("Het bestand dat u probeert te upload is te groot, maximaal: $maxsize bytes"); }[/quote:6ea8e9edab] Al moet ik bekennen dat ik niet weet waar $template->display() voor dient.
  • Hoi Supersnail, Bedankt fvoor je zeer uitgebreide antwoord :) ik krijg alleen een volgend probleempje.. zodra ik $collect['file'] = $_FILES['userfile']['name']; verander in $collect['file'] = $_FILES['userfile']['tmp_name']; Dan kan ik niks meer uploaden en krijg ik de melding dat het formaat niet klop dat zit um in dit stukje neem ik aan [code:1:b02d80a589]if ($check) { if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { move_uploaded_file($_FILES['userfile']['tmp_name'], "upload/" . $uploadname); //echo "Uw bestand met de naam: $uploadname is geupload."; } else echo'Uw bestand kon niet worden gupload'; } else { echo'Alleen de volgende formaten zijn toegestaan: jpg, mpg, avi, wmv en mov.'; die(); }[/code:1:b02d80a589] Maar de filesize check die werkt nu wel goed op jou manier alleen het hele uploaden niet meer :o heb je nog een tip of oplossing?
  • Er zit ook nog een t_engine.php bij het script misschien zit het wel daar in.. ik heb niet genoeg verstand van PHP om het te zien. ik vond hier veel informatie: http://www.developershome.com/wap/wapUpload/wap_upload.asp?page=php maar dan nog kom ik er niet uit, iemand die de fout ziet? [code:1:b0151dd127]<?PHP /* Jotti's template engine version 4 JTPL is distributed under specific license, see LICENSE for details. If your copy of JTPL did not include a LICENSE file, please visit: http://jotti.org/openlibs/jtpl/LICENSE Latest version is located at: http://jotti.org/openlibs/jtpl Some rudimentary documentation is available at: http://jotti.org/openlibs/jtpl/USAGE Copyright (C) 2002-2007 Jordi Bosveld <jotti@jotti.org> This is free software. Go insane. */ class jtpl { /* All functions and variables starting with an underscore "_" character are for internal use only. */ // debugging disabled by default var $debug = false; // where to read e.g. included template files from var $templateroot = "./"; // Normally we emulate trigger_error to obtain the correct line numbers etc., // but in projects where custom error handlers are used, this is a pain // so this feature can be disabled at runtime var $honor_errorhandler = false; // character set of the template var $charset = "ISO-8859-1"; // ignore preserves? var $ignorepreserves = false; // main template var $_template = ""; // current tree depth var $_depth = "/"; // current iteration var $_currentiteration = 0; // storage for variables, case blocks, if blocks var $_vars = array(); var $_ifblocks = array(); var $_caseblocks = array(); // timer for performance tracking var $_timer = 0; // template variable escapers var $_escapers = array("HTML" => "_escape_html", "XML" => "_escape_xml", "JS" => "_escape_js", "NL2BR" => "_escape_nl2br", "OOO" => "_escape_ooo", "URL" => "_escape_url", "TPL" => "_escape_tpl", "UCASE" => "_escape_ucase", "LCASE" => "_escape_lcase", "UCFIRST" => "_escape_ucfirst", "INT" => "_escape_int", "MONEY" => "_escape_money", "NOESCAPE" => "_escape_void"); // read a template from a file and use as root template // expects a template file name on the local filesystem function readtemplate($file) { $this->_settemplateroot($file); $data = $this->_readfile($file); $this->_template = $data; } // read template data from string and use as root template function assigntemplate($data) { $this->_template = $data; } // include a template as a variable // expects a template file name on the local filesystem function includetemplate($file, $variable) { $data = $this->_readfile($file); $this->assignvar($variable, $data); } // read a file from disk into a string function _readfile($file) { if (!is_file($file)) { $this->_trigger_jtplerror("Unable to open ".$file." as a template: file not found", E_USER_ERROR); } if (!is_readable($file)) { $this->_trigger_jtplerror("Unable to open ".$file." as a template: permission denied", E_USER_ERROR); } $data = file_get_contents($file); return $data; } // derive template path from assigned template file // used in dynamic includes to determine the right template directory, no matter // where the script itself is function _settemplateroot($filename) { if (preg_match("/(.*\/).*?/", $filename, $matches)) { $this->templateroot = $matches[1]; } else { $this->templateroot = "./"; } } // this function is used to display/handle errors // it will default to emulating trigger_error so correct line numbers // will be stated. function _trigger_jtplerror($errormessage, $errortype = E_USER_WARNING) { // let's honour the local PHP configuration when we 'emulate' // trigger_error() $htmlerrors = ini_get("html_errors"); if ($htmlerrors) { $boldprepend = "<b>"; $boldappend = "</b>"; $linebreak = "<br />\n"; } else { $boldprepend = ""; $boldappend = ""; $linebreak = "\n"; } switch ($errortype) { case E_USER_WARNING: $fatal = false; $messagetext = "Warning"; break; case E_USER_ERROR: $fatal = true; $messagetext = "Fatal error"; break; case E_USER_NOTICE: $fatal = false; $messagetext = "Notice"; break; default: // we should never arrive here, but let's put it in anyway... $fatal = true; $messagetext = "Unknown error"; break; } // get a backtrace $backtrace = debug_backtrace(); // reverse the array so the first item becomes the last, which // holds the entry important to us $backtrace = array_reverse($backtrace); $actualerror = $backtrace[0]; // these will not be too helpful when complaining about dynamic includes // or variable modifiers, but this way at least we're not blaming ourselves $file = $actualerror['file']; $linenumber = $actualerror['line']; if ($this->honor_errorhandler) { trigger_error($errormessage, $errortype); } else { echo $linebreak.$boldprepend.$messagetext.$boldappend.": ".$errormessage." in ".$boldprepend.$file.$boldappend." on line ".$boldprepend.$linenumber.$boldappend.$linebreak; } // if the error is fatal, we should consider our trek ended if ($fatal) { die; } } // this will parse the whole template on the fly function _buildtree($processdata, $depth = "/", $scope = array()) { $processeddata = ""; $text = ""; // iterate until there is nothing left while ($processdata != "") { $token = ""; // find the first occurence of { $firstcurl = strpos($processdata, "{"); if ($firstcurl > 0) { // first we have some text, then something // that may very well be a token $text .= substr($processdata, 0, $firstcurl); $processdata = substr($processdata, $firstcurl); } elseif ($firstcurl === false) { // only text left $text .= $processdata; $processdata = ""; } else { if (preg_match("/^{([a-z0-9_\-\.:;\|&]+)}/i", $processdata, $match)) { // possible real token $token = $match[1]; $processdata = substr($processdata, strlen($token) + 2); } elseif (preg_match("/^{!--.*?--}/s", $processdata, $match)) { // template comment, ignore the whole thing $processdata = substr($processdata, strlen($match[0])); } else { // probably something else... treat as text $text .= substr($processdata, 0, 1); $processdata = substr($processdata, 1); } } // let's see what kind of token we have here $tokentype = $this->_get_tokentype($token); // handle tokens appropriately if ($tokentype['type'] == "REPEAT" && $tokentype['starter']) { // we have a repeater! please iterate... $this->enterblock($tokentype['name']); $olddepth = $depth; if ($depth == "/") { $depth = $tokentype['name']; } else { $depth = $depth.":".$tokentype['name']; } if (!isset($this->_iterations[$depth])) { if ($this->debug) { $this->_trigger_jtplerror("REPEAT block '".$tokentype['name']."' never iterates at level ".$olddepth, E_USER_NOTICE); } $iterations = 0; } else { $iterations = $this->_iterations[$depth]; } // find out where this block ends if (!$tempdata = $this->_find_block_end($processdata, $tokentype['name'].":END")) { $this->_trigger_jtplerror("Encountered REPEAT block '".$tokentype['name']."' START token without accompanying END", E_USER_ERROR); } // we have to treat this repeat block as a 'separate' template in this subroutine $processdata = $tempdata['processdata']; $blockdata = $tempdata['blockdata']; for ($i = 1; $i <= $iterations; $i++) { // we need a different variable/if/case/etc. scope to parse this part // of the document. we pass on our current scope too, as 'parent' // variables etc., when not set in the repeat block itself, should be // inherited. $tempscope = $this->_createscope($depth."|".$i, $scope); $text .= $this->_buildtree($blockdata, $depth."|".$i, $tempscope); } $this->leaveblock(); $depth = $olddepth; } elseif ($tokentype['type'] == "IF" && $tokentype['starter']) { // IF block found $blockname = $tokentype['name']; if (!$tempdata = $this->_find_block_end($processdata, $blockname.":ENDIF")) { $this->_trigger_jtplerror("Encountered IF block '".$blockname."' IF token without accompanying ENDIF", E_USER_ERROR); } $processdata = $tempdata['processdata']; $ifdata = $this->_split_ifblock($tempdata['blockdata'], $blockname); // do we have AND/OR inside the IF block? if (strpos($blockname, "|") > 0 || strpos($blockname, "&") > 0) { // grab IF block names and & | AND/OR separators $matches = preg_split("/(&|\|)/", $blockname, -1, PREG_SPLIT_DELIM_CAPTURE); $operator = ""; $parttrue = false; foreach ($matches as $match) { if ($match == "|" || $match == "&") { $operator = $match; } else { $previousparttrue = $parttrue; // is this part supposed to be true? if (isset($scope['ifblocks'][$match])) { $parttrue = $scope['ifblocks'][$match]; } else { if ($this->debug) { $this->_trigger_jtplerror("IF block portion '".$match."' of IF block '".$blockname."' not set, reverting to FALSE", E_USER_NOTICE); } $parttrue = false; } if (($previousparttrue || $parttrue) && $operator == "|") { // we've found an OR that is true, no need // to continue $iftrue = true; break; } elseif (!$parttrue && $operator == "&") { // we've found an AND that is false, // no need to continue $iftrue = false; break; } } if ($operator == "&") { // if we survived our last AND operator without stumbling // upon something false, it must be true $iftrue = true; } else { // if we survived our last OR operator without stumbling // upon something true, it must be false $iftrue = false; } } } elseif (isset($scope['ifblocks'][$blockname])) { $iftrue = $scope['ifblocks'][$blockname]; } else { if ($this->debug) { $this->_trigger_jtplerror("IF block '".$blockname."' not set, reverting to FALSE", E_USER_NOTICE); } $iftrue = false; } if ($iftrue) { $blockdata = $ifdata['if']; } else { $blockdata = $ifdata['else']; } $text .= $this->_buildtree($blockdata, $depth, $scope); } elseif ($tokentype['type'] == "PRESERVE" && $tokentype['starter']) { // PRESERVE block found, don't parse anything inside it if (!$tempdata = $this->_find_block_end($processdata, "PRESERVE-END")) { $this->_trigger_jtplerror("Encountered PRESERVE-START token without accompanying PRESERVE-END", E_USER_ERROR); } if ($this->ignorepreserves) { $processdata = $tempdata['blockdata'].$tempdata['processdata']; } else { $processdata = $tempdata['processdata']; $text .= $tempdata['blockdata']; } } elseif ($tokentype['type'] == "CASE" && $tokentype['starter']) { // CASE block found $blockname = $tokentype['name']; // see where this block ends if (!$tempdata = $this->_find_block_end($processdata, $blockname.":CASE-END")) { $this->_trigger_jtplerror("Encountered CASE token without accompanying CASE-END", E_USER_ERROR); } $processdata = $tempdata['processdata']; $casedata = $this->_split_caseblock("{".$blockname.":".$tokentype['params'].":CASE}".$tempdata['blockdata'], $blockname); if (isset($scope['caseblocks'][$blockname])) { $case = $scope['caseblocks'][$blockname]; } else { if ($this->debug) { $this->_trigger_jtplerror("CASE block '".$blockname."' not set, reverting to DEFAULT", E_USER_NOTICE); } $case = "DEFAULT"; } if (!isset($casedata[$case])) { if (!isset($casedata['DEFAULT'])) { if ($this->debug) { $this->_trigger_jtplerror("CASE block '".$blockname."' has no CASE called '".$case."', leaving empty (no DEFAULT to fall back on)", E_USER_NOTICE); } $blockdata = ""; } else { if ($this->debug) { $this->_trigger_jtplerror("CASE block '".$blockname."' has no CASE called '".$case."', reverting to DEFAULT", E_USER_NOTICE); } $blockdata = $casedata['DEFAULT']; } } else { $blockdata = $casedata[$case]; } $text .= $this->_buildtree($blockdata, $depth, $scope); } elseif ($tokentype['type'] == "INCLUDE") { // this is an INCLUDE token, let's include the file specified $blockdata = $this->_readfile($this->templateroot.$tokentype['name']); if (!empty($tokentype['params'])) { $processdata = $this->modify_content($blockdata, $tokentype['params']).$processdata; } else { $processdata = $blockdata.$processdata; } } elseif ($tokentype['type'] == "ESCAPE" && $tokentype['starter']) { // ESCAPE block found, escape using the correct escaper(s) if (!$tempdata = $this->_find_block_end($processdata, $tokentype['params'].":ESCAPE-END")) { $this->_trigger_jtplerror("Encountered ESCAPE-START token without accompanying ESCAPE-END", E_USER_ERROR); } $processdata = $this->modify_content($tempdata['blockdata'], $tokentype['params']).$tempdata['processdata']; } elseif ($tokentype['ender']) { // we're never supposed to find these... switch ($tokentype['type']) { case "REPEAT": $this->_trigger_jtplerror("Encountered REPEAT block '".$tokentype['name']."' closing token without accompanying '{".$tokentype['name'].":START}'", E_USER_ERROR); break; case "IF": $this->_trigger_jtplerror("Encountered IF block '".$tokentype['name']."' closing token without accompanying '{".$tokentype['name'].":IF}", E_USER_ERROR); break; case "CASE": $this->_trigger_jtplerror("Encountered CASE block '".$tokentype['name']."' closing token without accompanying '{".$tokentype['name'].":...:CASE}'", E_USER_ERROR); break; case "PRESERVE": $this->_trigger_jtplerror("Encountered PRESERVE block closing token without accompanying '{PRESERVE-START}'", E_USER_ERROR); break; case "ESCAPE": $this->_trigger_jtplerror("Encountered ESCAPE block closing token without accompanying {...;ESCAPE-END}", E_USER_ERROR); break; } $this->_trigger_jtplerror("Encountered ".$tokentype['type']." block '".$tokentype['name']."' closing token without accompanying starting token", E_USER_ERROR); } // variables are a special case... we don't delegate these to ourselves since // variables aren't "blocks". if ($tokentype['type'] == "VARIABLE") { $var = $tokentype['name']; if (isset($scope['vars'][$var])) { // if no modifiers are present in template, use the default one, // if set if (!empty($this->defaultvarescape) && empty($tokentype['params'])) { $tokentype['params'] = $this->defaultvarescape; } if (!empty($tokentype['params'])) { $processdata = $this->modify_content($scope['vars'][$var], $tokentype['params']).$processdata; } else { $processdata = $scope['vars'][$var].$processdata; } } else { if ($this->debug) { $this->_trigger_jtplerror("VARIABLE '".$var."' not set", E_USER_NOTICE); } } } } return $text; } function _get_tokentype($token) { $tokentype = array("name" => "", "type" => "", "starter" => false, "ender" => false, "params" => ""); // what kind of token do we have... if (empty($token)) { // not a token at all } elseif ($token == "PRESERVE-START") { // PRESERVE start token $tokentype['type'] = "PRESERVE"; $tokentype['starter'] = true; } elseif ($token == "PRESERVE-END") { // PRESERVE end token (shouldn't find these, but oh well... $tokentype['type'] = "PRESERVE"; $tokentype['ender'] = true; } elseif (strpos($token, ":") === false) { // a plain old variable... 9 out of 10 tokens are plain old variables, match first $tokentype['type'] = "VARIABLE"; $tokentype['name'] = $token; // are there any modifiers? if (strpos($token, ";") !== false) { // apparently... // check which modifiers are there... $matches = explode(";", $token, 2); $tokentype['name'] = $matches[0]; if (isset($matches[1])) { $tokentype['params'] = $matches[1]; } } } else { // alright... some more difficult tag preg_match("/^(.*):(.*?)$/", $token, $matches); $data = $matches[1]; $type = $matches[2]; if ($type == "START") { $tokentype['type'] = "REPEAT"; $tokentype['starter'] = true; $tokentype['name'] = $data; } elseif ($type == "END") { $tokentype['type'] = "REPEAT"; $tokentype['ender'] = true; $tokentype['name'] = $data; } elseif ($type == "IF") { $tokentype['type'] = "IF"; $tokentype['starter'] = true; $tokentype['name'] = $data; } elseif ($type == "ENDIF") { $tokentype['type'] = "IF"; $tokentype['ender'] = true; $tokentype['name'] = $data; } elseif ($type == "CASE") { // we need to find the CASE name and options... if (!preg_match("/^(.*?):(.*)$/", $data, $match)) { $this->_trigger_jtplerror("Malformed CASE token: {".$matches[0]."}", E_USER_ERROR); } $tokentype['type'] = "CASE"; $tokentype['starter'] = true; $tokentype['name'] = $match[1]; $tokentype['params'] = $match[2]; } elseif ($type == "CASE-END") { $tokentype['type'] = "CASE"; $tokentype['ender'] = true; $tokentype['name'] = $data; } elseif ($type == "ESCAPE-START") { $tokentype['type'] = "ESCAPE"; $tokentype['starter'] = true; $tokentype['params'] = $data; } elseif ($type == "ESCAPE-END") { $tokentype['type'] = "ESCAPE"; $tokentype['ender'] = true; $tokentype['params'] = $data; } elseif (substr($type, 0, 7) == "INCLUDE") { $tokentype['type'] = "INCLUDE"; $tokentype['name'] = $data; // see if we have any escapers for this dynamic INCLUDE if (strlen($type) > 7 && preg_match("/^INCLUDE;([\w;]+)$/", $type, $matches)) { $tokentype['params'] = $matches[1]; } } } return $tokentype; } // this function will search for the end of some block function _find_block_end($processdata, $blockend) { if (!preg_match("/(.*?){".preg_quote($blockend, "/")."}(.*)$/s", $processdata, $matches)) { return false; } $data = array("processdata" => $matches[2], "blockdata" => $matches[1]); return $data; } // determine the IF and ELSE (if any) portions of the IF block function _split_ifblock($blockdata, $blockname) { if (!preg_match("/^(.*?){".preg_quote($blockname, "/").":ELSE}(.*?)$/s", $blockdata, $matches)) { // there is no ELSE... $if = $blockdata; $else = ""; } else { $if = $matches[1]; $else = $matches[2]; } $ifdata = array("if" => $if, "else" => $else); return $ifdata; } // determine the specific cases for this CASE block function _split_caseblock($blockdata, $blockname) { $blockname_preg = preg_quote($blockname, "/"); preg_match_all("/{".$blockname_preg.":(.*?):CASE}(.*?)(?={".$blockname_preg.":|$)/s", $blockdata, $matches); $cases = array(); foreach ($matches[1] as $key => $value) { $casedata = explode(":", $value); foreach ($casedata as $casetarget) { $cases[$casetarget] = $matches[2][$key]; } } return $cases; } // will modify content based on used escapers function modify_content($content, $modifiers) { $modifiers = preg_split("/;/", $modifiers); foreach ($modifiers as $modifier) { if (!isset($this->_escapers[$modifier])) { $this->_trigger_jtplerror("Unsupported variable modifier '".$modifier."' detected in template", E_USER_WARNING); continue; } $function = $this->_escapers[$modifier]; if (method_exists($this, $function)) { $content = $this->$function($content); } elseif (function_exists($function)) { $content = $function($content); } else { $this->_trigger_jtplerror("Unknown function '".$function."' for escaper '".$modifier."' ", E_USER_ERROR); } } return $content; } // this way you can add custom template escapers function add_custom_escaper($escapetag, $function) { $this->_escapers[$escapetag] = $function; } function _escape_html($content) { return htmlentities($content, ENT_QUOTES, $this->charset); } function _escape_js($content) { $content = preg_replace("/('|\"|\\\)/s", "\\\\$1", $content); $content = preg_replace("/(\r\n|\r|\n)/s", "\\n", $content); return $content; } function _escape_nl2br($content) { return nl2br($content); } function _escape_xml($content) { static $trans; $content = str_replace("&", "&" , $content); if(!isset($trans)) { $trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); foreach($trans as $key => $value) { $ord = ord($key); $trans[$key] = "&#".$ord.";"; } // dont translate the '&' in case it is part of &xxx; $trans[chr(38)] = '&'; } return strtr($content, $trans); } // "escapes" a string to OpenOffice.org encoding function _escape_ooo($string) { return iconv("WINDOWS-1252", "UTF-8", $this->_escape_xml($string)); } function _escape_url($content) { return rawurlencode($content); } function _escape_tpl($content) { $content = str_replace("{", "{", $content); $content = str_replace("}", "}", $content); return $content; } function _escape_ucase($content) { return strtoupper($content); } function _escape_lcase($content) { return strtolower($content); } function _escape_ucfirst($content) { return ucfirst($content); } function _escape_int($content) { return intval($content); } function _escape_money($content) { return sprintf("%.2f", $content); } function _escape_void($content) { return $content; } // assign a variable for use in a template (block) function assignvar($var, $content) { $depth = $this->_depth; $iteration = $this->_currentiteration; // iteration cannot be 0 when assigning variables if (empty($iteration) && $depth != "/") { $this->_trigger_jtplerror("Called assignvar() without prior startiteration()", E_USER_ERROR); } // no funky variable names please if (!preg_match("/^[a-z0-9_\.\-]+$/i", $var)) { $this->_trigger_jtplerror("' ".$var."' is not a valid variable name", E_USER_WARNING); } $this->_vars[$depth][$var] = $content; } // function to assign an entire array as vars (key => value) // by default array keys (vars) are capitalised function assignvarsfromarray($vars, $touppercase = true) { if (is_array($vars)) { foreach ($vars as $var => $val) { if ($touppercase) { $var = strtoupper($var); } $this->assignvar($var, $val); } } else { $this->_trigger_jtplerror("First argument supplied to assignvarsfromarray() is not an array", E_USER_WARNING); } } // assign an if block to the current iteration depth function ifblock($blockname, $condition) { $depth = $this->_depth; $iteration = $this->_currentiteration; if (empty($iteration) && $depth != "/") { $this->_trigger_jtplerror("Called ifblock() without prior startiteration()", E_USER_ERROR); } if (isset($this->_ifblocks[$depth]) && @array_key_exists($blockname, $this->_ifblocks[$depth]) && $this->debug) { $this->_trigger_jtplerror("IF block '".$blockname."' already declared", E_USER_WARNING); } $this->_ifblocks[$depth][strtoupper($blockname)] = $condition; } // assign a case block to the current iteration depth function caseblock($blockname, $condition) { $depth = $this->_depth; $iteration = $this->_currentiteration; if (empty($iteration) && $depth != "/") { $this->_trigger_jtplerror("Called caseblock() without prior startiteration()", E_USER_ERROR); } if (isset($this->_caseblocks[$depth]) && @array_key_exists($blockname, $this->_caseblocks[$depth]) && $this->debug) { $this->_trigger_jtplerror("CASE block '".$blockname."' already declared", E_USER_WARNING); } $this->_caseblocks[$depth][$blockname] = $condition; } // enter a template block "level" function enterblock($depth) { $currentdepth = $this->_depth; if ($currentdepth == "/") { if (isset($this->_iterations[$depth])) { $newdepth = $depth."|".intval($this->_iterations[$depth]); } else { $newdepth = $depth."|0"; } } else { if (isset($this->_iterations[$currentdepth.":".$depth])) { $newdepth = $currentdepth.":".$depth."|".intval($this->_iterations[$currentdepth.":".$depth]); } else { $newdepth = $currentdepth.":".$depth."|0"; } } $this->_depth = $newdepth; $this->_currentiteration = $this->_getcurrentiteration(); return true; } // leave a block "level" function leaveblock() { $currentdepth = $this->_depth; // we cannot go higher than the root level! if ($currentdepth == "/") { $this->_trigger_jtplerror("leaveblock(): already at root level", E_USER_ERROR); } $newdepth = preg_replace("/^(.*):.*?$/", "$1", $currentdepth); // the only time this regex will not replace anything, is when // we're about to ascend to the root level if ($newdepth == $currentdepth) { $newdepth = "/"; } $this->_depth = $newdepth; $this->_currentiteration = $this->_getcurrentiteration(); } // go back to root template (escape all repeat blocks) function torootblock() { $this->_depth = "/"; $this->_currentiteration = $this->_getcurrentiteration(); } // start an iteration for a repeat block function startiteration() { $depth = $this->_depth; // iterations on the root template do not make sense... if ($depth == "/") { $this->_trigger_jtplerror("Attempted to start an iteration for the root template", E_USER_ERROR); } $currentdepth = $this->_getcurrentdepth(); if (!isset($this->_iterations[$currentdepth])) { $this->_iterations[$currentdepth] = 0; } $this->_iterations[$currentdepth]++; $this->_increasedepthiteration(); $this->_currentiteration++; } function _getcurrentiteration() { return $this->_getiteration($this->_depth); } function _getiteration($depth) { if (preg_match("/^.*\|(\d+)$/", $depth, $matches)) { return $matches[1]; } else { return false; } } function _getcurrentdepth() { return $this->_getdepth($this->_depth); } function _getdepth($depth) { if (preg_match("/^(.*)\|\d+$/", $depth, $matches)) { return $matches[1]; } else { return "/"; } } function _increasedepthiteration() { $depth = $this->_getcurrentdepth(); if ($depth == "/") { return false; } $iteration = $this->_currentiteration; $iteration++; $newdepth = $depth."|".$iteration; $this->_depth = $newdepth; } // create a var/if/case scope for parsing content function _createscope($depth, $parentscope = false) { if (!$parentscope) { $parentscope = array("vars" => array(), "ifblocks" => array(), "caseblocks" => array()); } if (isset($this->_vars[$depth])) { $vars = array_merge($parentscope['vars'], $this->_vars[$depth]); } else { $vars = $parentscope['vars']; } if (isset($this->_ifblocks[$depth])) { $ifblocks = array_merge($parentscope['ifblocks'], $this->_ifblocks[$depth]); } else { $ifblocks = $parentscope['ifblocks']; } if (isset($this->_caseblocks[$depth])) { $caseblocks = array_merge($parentscope['caseblocks'], $this->_caseblocks[$depth]); } else { $caseblocks = $parentscope['caseblocks']; } $scope = array("vars" => $vars, "ifblocks" => $ifblocks, "caseblocks" => $caseblocks); return $scope; } // simple function to get current time function _gettime() { $timer = explode(" ", microtime()); $timer = $timer[0] + $timer[1]; return $timer; } // this will render the template function _process() { $timer = $this->_gettime(); // reset template iterator before processing $this->_depth = ""; $data = $this->_template; // we need a variable/if/case/etc. scope to parse the document $scope = $this->_createscope("/"); $document = $this->_buildtree($data, "/", $scope); $timer = $this->_gettime() - $timer; $this->_timer = $timer; return $document; } // return the generated document function getdocument() { $document = $this->_process($this->_template); return $document; } // display the generated document function display() { $document = $this->_process($this->_template); echo $document; } } ?>[/code:1:b0151dd127] En had ik nog een vraagje.. waar is deze t_engine.php voor? bij andere upload scrips kwam ik deze helemaal niet tegen.
  • Ik denk dat het probleem bij de check zit. Ik kan me zo voorstellen dat PHP het bestand opslaat onder een tijdelijke naam (iets als uploadxxxx of gewoon een reeks willekeurige tekens) en dus ook zonder extensie. Ik zou [quote:fa0d421306]upload($collect['file']);[/quote:fa0d421306] vervangen door [quote:fa0d421306]upload(basename($_FILES['name']));[/quote:fa0d421306] Je wilt sowieso alleen de basename (bestandsnaam) doorgeven en niet het complete pad. Overigens zou ik ook nog even nadenken over de extensiecheck. Wat voor ergs kan er gebeuren als iemand een ander bestand de extensie jpg geeft en hem upload?
  • Ik had de extencie check al uit gezet om te kijken wat die dan zou doen maar zodra die name is veranderd in tmp_name dan werkt het hele script niet meer. Ik weet niet in hoevere het velig is als iemand exe of php files kan uploaden in een map waar ze read en write rechten in hebben. Maar de extensie check uit zetten heeft geen nut helaas.. volgens mij moet het script theoretisch gewoon kloppen maar waarom die nou vast loopt?????
  • Wat heb je, naast de tmp_name, nog veranderd en wat doet je script nu wat hij niet moet doen of andersom en hoe weet je dat (foutmelding?).
  • Ik heb het hele filecheck gebeuren voor de extencie uit gezet om te kijken of hij dan wel upload maar dat doet die niet. Maar de maxsize check die werkt dan wel goed, ik krijg een melding als het bestand groter is dan de toegestaande waarde, alleen hij upload het bestand daarna niet. Hij geeft dan wel de melding dat het bestand goed is geupload maar er komt niks in het upload mapje, het mapje heeft 777 rechten. Ik krijg dan wel niet meer de melding dat de extencie niet klopt maar dat is wel logisch want die echo staat dan ook uit. Dit gebeurt als ik $collect['file'] = $_FILES['userfile']['tmp_name']; gebruik. Gebruik ik $collect['file'] = $_FILES['userfile']['name']; dan werkt het hele script goed maar dan heb ik weer geen maxsize check. Ik krijg dan geen foutmelding of iets hij slaat gewoon die hele mxsize check over lijkt het wel.
  • Kan je toch eens proberen om "upload(basename($_FILES['userfile']['name']));" te gebruiken? [quote:7f0d5b7495]move_uploaded_file($_FILES['userfile']['tmp_name'], "upload/" . $uploadname);[/quote:7f0d5b7495] Als $uploadname gelijk is aan $_FILES['tmp_name'] wordt geprobeerd om het geuploade (weet iemand hoe je dit woord spelt?) te kopieren naar "upload/volledige/pad/naar/tijdelijk_bestand". Al begrijp ik niet dat het dan wel werkt als $uploadname gelijk is aan $_FILES['name']. Kijk anders ook eens op http://nl2.php.net/manual/en/features.file-upload.php
  • He Supersnail, Mijn dank is ZEEEEEEEEEER groot, het werkt :D ik begrijp uit je woorden dat het script niet helemaal logisch in elkaar zit. En ik zelf heb veelste weinig verstand van PHP om de logica te zien. Maar ben wel happy dat het eindelijk helemaal werkt zoals ik wou. Super bedankt!!!!!
  • Graag gedaan. Mooi dat het nu werkt. Ik begrijp uit jouw woorden dat je het script niet zelf hebt geschreven? De maker heeft idd een aantal vreemde keuzes gemaakt die de duidelijkheid van het script niet ten goede komen.
  • Hoi, nee klopt het was een bestaand upload script die ik iets had aangepast aan mijn wensen. ik post hem nu op php freaks want kon daar niks goeds vinden en nu hebben anderen er ook nog wat aan want hij werkt perfect. :)

Beantwoord deze vraag

Weet jij het antwoord op deze vraag? Registreer of meld je aan met je account

Dit is een gearchiveerde pagina. Antwoorden is niet meer mogelijk.