1
你能幫我解決這個問題嗎? 我需要使用一些簡單的腳本在上傳時調整圖像大小。我需要在上傳時調整圖像大小
CODE:
<form method="post" enctype="multipart/form-data">
<input type="file" name="obrazky[]" />
<input type="submit" value="Nahrát na server!" />
</form>
<?php
// konfigurace
$uploadDir = 'imgs/nahrane'; // dir
$allowedExt = array('jpg', 'jpeg', 'png', 'gif'); // ok formats
if(isset($_FILES['obrazky']) && is_array($_FILES['obrazky']['name'])) {
$counter = 0;
$allowedExt = array_flip($allowedExt);
foreach($_FILES['obrazky']['name'] as $klic => $nazev) { // make variable $nazev
$nazev = htmlspecialchars($nazev, ENT_QUOTES);
$fileName = basename(time() . ".png");
$fileName = sprintf(time() . ".png", pathinfo($nazev, PATHINFO_EXTENSION));
$tmpName = $_FILES['obrazky']['tmp_name'][$klic];
$fileName = htmlspecialchars($fileName, ENT_QUOTES);
// check
if(
!is_uploaded_file($tmpName)
|| !isset($allowedExt[strtolower(pathinfo($fileName, PATHINFO_EXTENSION))])
) {
// bad format
continue;
}
// move
if(move_uploaded_file($tmpName, "{$uploadDir}".DIRECTORY_SEPARATOR."{$fileName}")) {
++$counter;
}
}
if ($counter > 0)
echo "<hr><p>Uploaded {$counter} z ".sizeof($_FILES['obrazky']['name'])." thank you!<br>
<br>
<b>LINKS</b>:<br>
href:<br>
<a href='$uploadDir/$fileName' target='_blank'>$uploadDir/$fileName</a><br>
else
echo "<hr><b><font color='red'>ERROR: Bad format or no image uploaded.</font></b><br>";
}
?>
我沒有媒體鏈接在谷歌搜索和計算器,我試過媒體鏈接的東西,但我不得到它的工作。
使用這個類其簡單和強大[鏈接](https://www.verot.net/php_class_upload.htm) –
看看這個: [http://stackoverflow.com/questions/18805497/php-調整圖像上上傳](http://stackoverflow.com/questions/18805497/php-resize-image-on-upload) –