php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2005-2

 
 
LinkBack Themen-Optionen Bewertung: Bewertung: 1 Stimmen, 1,00 durchschnittlich.
Alt 30.06.2005, 13:56  
Moderator
 
Benutzerbild von robo47
 
Registriert seit: 03.09.2004
Beiträge: 11.792
PHP-Kenntnisse:
Fortgeschritten
robo47 kann auf vieles stolz seinrobo47 kann auf vieles stolz seinrobo47 kann auf vieles stolz seinrobo47 kann auf vieles stolz seinrobo47 kann auf vieles stolz seinrobo47 kann auf vieles stolz seinrobo47 kann auf vieles stolz seinrobo47 kann auf vieles stolz sein
Standard

error_reporting(E_ALL); an den anfang des scripts ?
und dann schauen was für fehlermeldungen kommen ?

abgesehen davon, setze mal für

$uploaddir
einen absoluten pfad ein nciht so ein komsiches ./name-zeug

mfg
robo47
robo47 ist offline  
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 30.06.2005, 15:14  
Gast
 
Beiträge: n/a
Standard

Besten Dank an Alle! error_reporting hat gefunzt wie nix.
Hab nochmals etliches gefixed und das ganze vollendet. Sozusagen als dankeschön an die Menschheit

Hier ist das fertige LAUFFÄHIGE skript

PHP-Code:
 <?
error_reporting
(E_ALL);    //showing all php problems

 
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
    
//- TURN ON THIS DEBUG INFO, IF YOU NEED HELP
    //echo 'Here is some debugging info:';
    //print_r($_FILES);
    //echo '
';

    /* SUBMITTED INFORMATION - use what you need
     * errorcode                   : $errorcode
     * original filename           : $imgfile_name
     * temporary filename          : $imgfile_temp
     * size of uploaded file       : $imgfile_size
     * mime-type of uploaded file  : $imgfile_mimetype
     */
     $errorcode = ($_FILES['
imgfile']['error']);         // 0 is good
     $imgfile_temp = ($_FILES['
imgfile']['tmp_name']);
     $imgfile_name = ($_FILES['
imgfile']['name']);
     $imgfile_size = ($_FILES['
imgfile']['size']);
     $imgfile_mimetype = ($_FILES['
imgfile']['type]);

     
/*== upload directory where the file will be stored
          relative to where script is run ==*/
    
$uploaddir ".\\";             // this is the currentdir .\ for windows, please change to your os (preffered linux)
    
    
if ($errorcode!=0)
    {
     
//there was probalby no file given
     
$error1="<h1>ERROR</h1>Please specify a file for uploading
"
;
    }
    else  
//errocode = 0
    
{
      
/* get file extension  ==*/
      
$fileExtension strrchr($imgfile_name,".");
      
/*== check fileextesion, if not correct do not allow upload ==*/
      // echo  "name: ".$imgfile_name."filextension: ".$fileExtension;
      
$fileExtension strtolower($fileExtension);
      if ((
$fileExtension != ".jpg")  && ($fileExtension != ".jpeg"))
      {
        
$error1 =  "<h1>ERROR</h1>Image Extension Unknown.
"
;
        
$error2 "Please upload only a JPEG image with the extension .jpg or .jpeg ONLY
"
;
        
$error3 "The file you uploaded had the following extension: $fileExtension</p>\n";
        
/*== delete uploaded file ==*/
        //unlink($imgfile_name);
      
}
      else
      {
        
//-- CHECK FILE SIZE OF UPLOADED IMAGE
        
$maxfilesize 100000;  //in bytes  , 1024 = 1 Kbyte
        
        
if ($imgfile_size >  $maxfilesize)
        {
          
$error1 "
<h2>ERROR</h2>Imagesfilesize is bigger as "
.$maxfilesize;
          
$error2 "
Your file has the size "
.$imgfile_size."
"
;
        }
        else
        {
          
//-- CHECK IMAGE SIZE OF UPLOADED IMAGE
          
$imgsize GetImageSize($imgfile_temp);
          
/*== check size  0=width, 1=height ==*/
          
$maxwidth 2500;
          
$maxheight 2500;
          if ((
$imgsize[0] > $maxwidth) || ($imgsize[1] > $maxheight))
          {
            
$error1 "
<h2>ERROR</h2>Imageszize is bigger as "
.$maxwidth."x".$maxheight;
            
$error2 "
Your image has width "
.$imgsize[0]." and height ".$imgsize[1]."
"
;
          }
          else
          {
            
/*== setup final file location and name ==*/
            /*== change spaces to underscores in filename  ==*/
            
$final_filename str_replace(" ""_"$imgfile_name);
            
$newfile $uploaddir.$final_filename;
            
/*== do extra security check to prevent malicious abuse==*/
            
if (is_uploaded_file($imgfile_temp))
            {
              
/*== the file exists only temporary therefore we copy file to proper directory ==*/
              //if (!copy($imgfile,$newfile))
              
if (!move_uploaded_file($imgfile_temp,$newfile))
              {
                
/*== if an error occurs the file could not be written, read or possibly does not exist ==*/
                
print "Error Uploading File.";
              }
              else
              {
               
//- DEBUG INFO
               //echo"File is succesfully copied to ".$newfile;
             
               
$newimage "<img src=\"".$final_filename."\">";
                
/*== DO WHATEVER ELSE YOU WANT
                  SUCH AS INSERT DATA INTO A DATABASE  ==*/
              
}
            }
          }
       }
      }
    }
}
else
{
    
$debug "POST conditions are not true";
}
?>

<html>
<head>
    <title>Image upload test</title>
</head>

<body bgcolor="#FFFFFF">

   <? if (isset($error1)) echo $error1 ?>
   <? if (isset($error2)) echo $error2 ?>
   <? if (isset($error3)) echo $error3 ?>
   <? if (isset($newimage)) echo $newimage."
?>

    <h2>Upload an Image</H2>

    <form action="upload-test.php" method="POST" enctype="multipart/form-data">

    

Upload Image: <input type="file" name="imgfile">

    <font size="1">Click browse to upload a local file</font>

    

    <input type="submit" value="Upload Image">
    </form>

</body>
</html>
 
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Upload Script hat Probleme mit versch. Browsern [MimeType] fdm PHP Tipps 2008 11 27.07.2008 23:35
Upload Script + Multible Server cyberstorm PHP Tipps 2006 5 11.10.2006 19:43
Probelem bei meinem Upload Script für Bilder wiegia086 PHP Tipps 2006 3 17.03.2006 09:14
Daten Upload Script Hilfe!! PHP Tipps 2007 9 29.12.2005 10:39
Suche Upload Script Beitragsarchiv 1 20.07.2005 15:26
Upload Script PHP Tipps 2005-2 8 01.07.2005 08:45
upload script ändern PHP Tipps 2005 30 23.03.2005 20:30
suche upload script Beitragsarchiv 6 14.02.2005 22:25
Upload Script funktioniert lokal nicht?! TheTommynator PHP Tipps 2005 16 22.01.2005 23:42
Upload Script. PHP Tipps 2004 4 05.11.2004 10:53
Ich bin auf der Suche nach einem fertigen Menü Upload Script Beitragsarchiv 7 22.08.2004 18:53
Upload mit Fehlermeldung "The script whose uid is 982 i PHP Tipps 2004 2 06.07.2004 13:18

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
$imgfile_size =, [error] => 0 [size] bild upload, php upload script (image or picture) img src -resize, php $imgfile[\'error\'] 2, click browse to upload

Alle Zeitangaben in WEZ +2. Es ist jetzt 04:40 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.