<form id="form" name="form" method="post" action="process_image.php">
<textarea name="urls" cols="60" rows="10"></textarea>
<input type="submit" value="Upload Images" />
</form>
我应该在此代码中添加什么来自动调整图像大小,以宽度:175px和高度:自动
<?PHP
$urls = $_POST['urls'];
$list = explode("\n", $urls);
if (!file_exists("images")) {
mkdir("images", 0755);
}
$files = array();
foreach ($list as $links) {
$image = get_image($links);
$file = 'images/' . img_name($links);
file_put_contents($file, $image);
array_push($files, $file);
}
function get_image($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function img_name($url) {
$chars = array_merge(range(a, z), range(0, 9));
$extension = get_extension($url);
$name = "";
do {
for($i = 0; $i < 6; $i++) {
$name .= $chars[rand(0, (count($chars) - 1))];
}
} while (file_exists('images/$name.$extension'));
return $name . "." . $extension;
}
function get_extension($url) {
$ext_pos = strpos(strrev($url), ".");
$ext = substr($url, (strlen($url) - $ext_pos), $ext_pos);
return $ext;
}
?>
在这里显示网址:
<form name="form_process">
<label>Images Uploaded</label>
<textarea id="image_urls" cols="50" rows="10"><?PHP
foreach($files as $uploaded) {
echo "http://".$_SERVER['HTTP_HOST']. "/" .$uploaded . "\n";
}
?></textarea>
</form>