Hej Igen,
Jeg forsøger nu at benytte mig af en fileupload funktion i php. (phuploader.php)
Når jeg forsøger at uploade et billede står der "General upload failure"
Den siger ikke mere om hvad fejlen er.
jeg prøver så at debugge koden for at finde ud af hvad der går galt.
Alle echoerne bliver udskrevet undtagen 1, men jeg går ud fra at det er fordi jeg ikke har sat kodeord på.
Er der en der ved hvad problemet kunne være.
Nogle andre billeder virker, men nogle gør ikke.
Det her er koden:
- // Max size PER file in KB
- $max_file_size="5000";
-
- // Max size for all files COMBINED in KB
- $max_combined_size="5000";
-
- //Maximum file uploades at one time
- $file_uploads="1";
-
- //The name of your website
- $websitename="Upload the picture you want as a profile picture on facebook and type in your email. A moment later you will recieve an e-mail with your new profile picture. ";
-
- // Full browser accessable URL to where files are accessed. With trailing slash.
- $full_url="http://YOUR_SITE/uploads/";
-
- // Path to store files on your server If this fails use $fullpath below. With trailing slash.
- $folder="./uploads/";
-
- // Use random file names? true=yes (recommended), false=use original file name.
- // Random names will help prevent files being denied because a file with that name already exists.
- $random_name=true;
-
- // Types of files that are acceptiable for uploading. Keep the array structure.
- $allow_types=array("jpg","gif","png","zip","rar","txt","doc");
-
- // Only use this variable if you wish to use full server paths. Otherwise leave this empty. With trailing slash.
- $fullpath="";
-
- //Use this only if you want to password protect your upload form.
- $password="";
-
- /*
- //================================================================================
- * ! ATTENTION !
- //================================================================================
- : Don't edit below this line.
- */
-
- // Initialize variables
- $password_hash=md5($password);
- $error="";
- $success="";
- $display_message="";
- $file_ext=array();
- $password_form="";
-
- // Function to get the extension a file.
- function get_ext($key) {
- $key=strtolower(substr(strrchr($key, "."), 1));
- $key=str_replace("jpeg","jpg",$key);
- return $key;
- }
-
- // Filename security cleaning. Do not modify.
- function cln_file_name($string) {
- $cln_filename_find=array("/\.[^\.]+$/", "/[^\d\w\s-]/", "/\s\s+/", "/[-]+/", "/[_]+/");
- $cln_filename_repl=array("", ""," ", "-", "_");
- $string=preg_replace($cln_filename_find, $cln_filename_repl, $string);
- return trim($string);
- }
-
- // If a password is set, they must login to upload files.
- If($password) {
-
- //Verify the credentials.
- If($_POST['verify_password']==true) {
- If(md5($_POST['check_password'])==$password_hash) {
- setcookie("phUploader",$password_hash);
- sleep(1); //seems to help some people.
- header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
-
- exit;
- echo "1";
- }
-
- }
-
-
- //Show the authentication form
- If($_COOKIE['phUploader']!=$password_hash) {
- $password_form="<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
- $password_form.="<table align=\"center\" class=\"table\">\n";
- $password_form.="<tr>\n";
- $password_form.="<td width=\"100%\" class=\"table_header\" colspan=\"2\">Password Required</td>\n";
- $password_form.="</tr>\n";
- $password_form.="<tr>\n";
- $password_form.="<td width=\"35%\" class=\"table_body\">Enter Password:</td>\n";
- $password_form.="<td width=\"65%\" class=\"table_body\"><input type=\"password\" name=\"check_password\" /></td>\n";
- $password_form.="</tr>\n";
- $password_form.="<td colspan=\"2\" align=\"center\" class=\"table_body\">\n";
- $password_form.="<input type=\"hidden\" name=\"verify_password\" value=\"true\">\n";
- $password_form.="<input type=\"submit\" value=\" Verify Password \" />\n";
- $password_form.="</td>\n";
- $password_form.="</tr>\n";
- $password_form.="</table>\n";
- $password_form.="</form>\n";
-
- }
-
- } // If Password
- echo "2";
- // Dont allow submit if $password_form has been populated
- If(($_POST['submit']==true) AND ($password_form=="")) {
- echo "3";
- //Tally the size of all the files uploaded, check if it's over the ammount.
- If(array_sum($_FILES['file']['size']) > $max_combined_size*5000) {
-
- $error.="<b>FAILED:</b> All Files <b>REASON:</b> Combined file size is to large.<br />";
-
- // Loop though, verify and upload files.
- } Else {
- echo "4";
- // Loop through all the files.
- For($i=0; $i <= $file_uploads-1; $i++) {
-
- // If a file actually exists in this key
- If($_FILES['file']['name'][$i]) {
- echo "5";
- //Get the file extension
- $file_ext[$i]=get_ext($_FILES['file']['name'][$i]);
-
- // Randomize file names
- If($random_name){
- $file_name[$i]=time()+rand(0,100000);
- } Else {
- $file_name[$i]=cln_file_name($_FILES['file']['name'][$i]);
- }
- echo "6";
- // Check for blank file name
- If(str_replace(" ", "", $file_name[$i])=="") {
-
- $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Blank file name detected.<br />";
-
- //Check if the file type uploaded is a valid file type.
- } ElseIf(!in_array($file_ext[$i], $allow_types)) {
-
- $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Invalide file type.<br />";
-
- //Check the size of each file
- } Elseif($_FILES['file']['size'][$i] > ($max_file_size*1024)) {
-
- $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File to large.<br />";
-
- // Check if the file already exists on the server..
- } Elseif(file_exists($folder.$file_name[$i].".".$file_ext[$i])) {
-
- $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File already exists.<br />";
-
- } Else {
-
- If(move_uploaded_file($_FILES['file']['tmp_name'][$i],$folder.$file_name[$i].".".$file_ext[$i])) {
-
- $success.="<b>SUCCESS:</b> ".$_FILES['file']['name'][$i]."<br />";
- $success.="<b>URL:</b> <a href=\"".$full_url.$file_name[$i].".".$file_ext[$i]."\" target=\"_blank\">".$full_url.$file_name[$i].".".$file_ext[$i]."</a><br /><br />";
-
- } Else {
- $error.="<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> General upload failure.<br />";
Som i kan se, er det den nederste linje som bliver udskrevet, men der står ikke hvad problemet er hvis det er denne som bliver udskrevet
Tak for hjælpen
Indlæg senest redigeret d. 03.10.2012 22:49 af Bruger #14317