2014-11-20 2 views
1

암은 단일 입력에서 여러 이미지를 업로드하고 엄지 양식을 즉시 업로드 된 모든 이미지를 만들하지만 난이 코드를 실행하면 내가 검은 색으로 만 이미지를 얻을 수 있지만, 업로드로 orginal 한 이미지가 동일는 BLACK

내가 을 발생 모르는 코드를 실행하면
$orig_directory = "$desired_dir"; //Full image folder 
$thumb_directory = "thumb/"; //Thumbnail folder 

/* Opening the thumbnail directory and looping through all the thumbs: */ 
$dir_handle = @opendir($orig_directory); //Open Full image dirrectory 
if ($dir_handle > 1){ //Check to make sure the folder opened 

$allowed_types=array('jpg','jpeg','gif','png'); 
$file_type=array(); 
$ext=''; 
$title=''; 
$i=0; 

while ($file_name = @readdir($dir_handle)) { 
    /* Skipping the system files: */ 
    if($file_name=='.' || $file_name == '..') continue; 

    $file_type = explode('.',$file_name); //This gets the file name of the images 
    $ext = strtolower(array_pop($file_type)); 

    /* Using the file name (withouth the extension) as a image title: */ 
    $title = implode('.',$file_type); 
    $title = htmlspecialchars($title); 

    /* If the file extension is allowed: */ 
    if(in_array($ext,$allowed_types)) { 

     /* If you would like to inpute images into a database, do your mysql query here */ 

     /* The code past here is the code at the start of the tutorial */ 
     /* Outputting each image: */ 

     $nw = 100; 
     $nh = 100; 
     $source = "$desired_dir{$file_name}"; 
     $stype = explode(".", $source); 
     $stype = $stype[count($stype)-1]; 
     $dest = "thumb/{$file_name}"; 

     $size = getimagesize($source); 
     $w = $size[0]; 
     $h = $size[1]; 

     switch($stype) { 
      case 'gif': 
       $simg = imagecreatefromgif($source); 
       break; 
      case 'jpg': 
       $simg = imagecreatefromjpeg($source); 
       break; 
      case 'png': 
       $simg = imagecreatefrompng($source); 
       break; 
     } 

     $dimg = imagecreatetruecolor($nw, $nh); 
     $wm = $w/$nw; 
     $hm = $h/$nw; 
     $h_height = $nh/2; 
     $w_height = $nw/2; 

     if($w> $h) { 
      $adjusted_width = $w/$hm; 
      $half_width = $adjusted_width/2; 
      $int_width = $w/$hm; 
      imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); 
     } else { 
      imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h); 
     } 
      imagejpeg($dimg,$dest,100); 
     } 
} 

/* Closing the directory */ 
@closedir($dir_handle); 

} 
?> 

은 내가

답변

0

다음 코드를 사용하여 엄지 손가락 위의이 검은 색에 오류가 검은 색으로 만 이미지를 얻을

<html> 
    <body> 
     <pre><? 
      print_r($_FILES); //SHOW THE ARRAY 

      foreach ($_FILES as $file) { 
       if (!$file['error']) { 
        //PROCESS THE FILE HERE 
        echo $file['name']; 
       } 
      } 
     ?></pre> 

     <script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script> 
     <script type="text/javascript"> 

      var fd = new FormData(); 
      $(document).ready(function() { 

       //submit dragdropped by ajax 
       $("#dropsubmit").on("click", function(e) { 
        $.ajax({   
         data: fd, 
         processData: false, 
         contentType: false, 
         type: 'POST', 
         success: function(data){ 
          //FILES POSTED OK! REDIRECT 
          console.log(data); 
         } 
         }); 
       }) 

       var dropzone = $("#dropzone"); 
       dropzone.on('dragenter', function (e) { 
        $(this).css('background', 'lightgreen'); 
       }); 

       //dropped files, store as formdata 
       dropzone.on('dragover', stopPropagate); 
       dropzone.on('drop', function (e) { 
        stopPropagate(e) 
        $(this).css('background', 'white'); 
        var files = e.originalEvent.dataTransfer.files; 

        for (var i = 0; i < files.length; i++) { 
         preview(files[i]) 
         fd.append('file' + (i + 1), files[i]); 
         if (i >= 5) continue 
        } 

       }); 
       function stopPropagate(e) { 
        e.stopPropagation(); 
        e.preventDefault(); 
       } 


       if (window.File && window.FileList && window.FileReader) { 
        $("input[type=file]").on("change", function(e) { 
         preview(e.target.files[0]) 
        }); 
       } else { 
        alert("Your browser doesn't support to File API") 
       } 

       function preview(item) { 
        var fileReader = new FileReader(); 
        fileReader.onload = (function(e) { 
         var file = e.target; 
         $("<img></img>", { 
          class: "imageThumb", 
          src: file.result, 
          title: file.name, 
         }).appendTo("#images"); 
        }); 
        fileReader.readAsDataURL(item); 
       } 
      }); 
     </script> 

     <div id="dropzone" style="width:100px;height:100px;border:2px dashed gray;padding:10px">Drag & Drop Files Here</div> 
     <input type="button" id="dropsubmit" value="Submit dropped files" /> 
     <hr> 
     <form method="post" enctype="multipart/form-data"> 
      <input id="file1" name="file1" type="file"/><br> 
      <input id="file2" name="file2" type="file"/><br> 
      <input id="file3" name="file3" type="file"/><br> 
      <input id="file4" name="file3" type="file"/><br> 
      <input id="file5" name="file3" type="file"/><br> 
      <input name="submit" type="submit" value="Upload files" /> 
     </form><div id="images"></div> 
    </body> 
</html>