0

MrCode のリードに従って、アップロードが他の画像形式で行われなかった理由を検出できました。以下は createThumbs 関数です。他の拡張機能で機能させるにはどうすればよいですか。

<?php
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) 
{
 // open the directory
$dir = opendir( $pathToImages );

// loop through it, looking for any/all JPG files:
while (false !== ($fname = readdir( $dir ))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if ( strtolower($info['extension']) == 'jpg' ) 
{
  // load image and get image size
  $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
  $width = imagesx( $img );
  $height = imagesy( $img );

  // calculate thumbnail size
  $new_width = $thumbWidth;
  $new_height = floor( $height * ( $thumbWidth / $width ) );

  // create a new tempopary image
  $tmp_img = imagecreatetruecolor( $new_width, $new_height );

  // copy and resize old image into new image 
  imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width,   $height );

  // save thumbnail into a file
  imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
}
}
// close the directory
closedir( $dir );
}

?>
4

1 に答える 1

0

問題はあなたのループにあると思います

foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){

のように書くべきです

foreach($_FILES['files'] as $key => $file){

最初は初めて実行され、最初はイメージfileがある可能性があるjpegため、初めて実行されます。

于 2013-02-21T11:16:47.590 に答える