내 웹 사이트에 이미지를 업로드하기 위해 uploadify를 사용하고 있습니다.
훌륭한 제품이지만 썸네일이 제대로 작동하지 않습니다.
내가 찾은 일부 코드를 수정했으며 잘 작동하며 한 번에 원하는만큼 많은 이미지를 업로드하지만 각 이미지를 업로드하면 이전 이미지를 덮어 쓰므로 업로드 폴더에 하나의 이미지와 하나의 엄지 손가락 만 남습니다.
내가 사용하는 코드는 다음과 같습니다.
<?php
// Define a destination
$targetFolder = '../uploadifythumbtest'; // Relative to the root
$thumbsFolder = '../uploadifythumbtest/thumbs/'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $targetFolder;
$fileParts = pathinfo ( $_FILES ['Filedata'] ['name'] );
$extension = $fileParts ['extension'];
$filename = "artist_" . $yourid . "." . $fileParts ['extension'];
$targetFile = rtrim ( $targetPath, '/' ) . '/' . $filename;
$targetThumb = rtrim ( $thumbsFolder, '/' ) . '/' . $filename;
// Validate the file type
$fileTypes = array (
'jpg',
'jpeg',
'gif',
'png',
'JPG',
'bmp'
); // File extensions
if (in_array ( $fileParts ['extension'], $fileTypes )) {
// CREATE THUMBNAIL
if ($extension == "jpg" || $extension == "jpeg") {
$src = imagecreatefromjpeg ( $tempFile );
} else if ($extension == "png") {
$src = imagecreatefrompng ( $tempFile );
} else {
$src = imagecreatefromgif ( $tempFile );
}
list ( $width, $height ) = getimagesize ( $tempFile );
$newwidth = 50;
$newheight = ($height / $width) * $newwidth;
$tmp = imagecreatetruecolor ( $newwidth, $newheight );
imagecopyresampled ( $tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
$thumbname = $targetThumb;
imagejpeg ( $tmp, $thumbname, 100 );
imagedestroy ( $src );
imagedestroy ( $tmp );
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
?>
이미지를 저장하는 데 사용되는 파일 이름은 다음 줄에 생성됩니다.
$filename = "artist_" . $yourid . "." . $fileParts ['extension'];
따라서 업로드하는 모든 파일의 이름은 동일합니다.
원래 파일 이름 파일 이름을 사용할 수 있습니다.
$filename = $fileParts['filename']. "." . $fileParts ['extension'];
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다