While uploading images i encounter a header problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

While uploading images i encounter a header problem

Post by fastfingertips »

I'm uploading images, PHP wrote them in the right folder (extension is ok, size is ok) but when i'm trying top open them with an image viewer is telling me that it can't recognize file header :(

Code: Select all

<?php
function UploadItem() {
    $ValidExt=0;
    if($this->itemSize > $this->itemSizeAllowed) { 
      $this->error .= 'The file has a size greate the maximum allowed('.$this-> $this->itemSizeAllowed.').<br>'; 
    }      
    $fileDetails=pathinfo($this->itemName);
    $this->itemExtension=$fileDetails['extension'];
    $this->itemBasename=$fileDetails['basename'];
    //Now verifying the file name
    if(strlen($this->itemBasename)>254) {
      $this->error .= "File name is to long, it must have a lenght under 254 characters.<br>";
    }
    //Now verifying extension
    foreach($this->allowedExtensions[$this->type] as $key => $ext) {      
      if(strcasecmp($ext, $this->itemExtension) == 0) {          
          $ValidExt = 1; 
          break; 
      }
    }
    if($ValidExt==1) {
      if(empty($this->error)) {        
        if(is_uploaded_file($this->itemNameTemporar)) {
          $tmp_target="";
          $tmp_target=$this->targetDirector[$this->type].$this->itemName;          
          move_uploaded_file($this->itemNameTemporar, $tmp_target); 
        } 
      }
    }
    else {
      echo $this->itemType;
      $this->error .= "Only the following extensions are allowed: ";
      foreach($this->allowedExtensions[$this->type] as $key=>$value) {
        $this->error .=' .'.$value;
      }
    }
  }
?>
Post Reply