在上传时调整图像大小,然后调整move_upload_file函数

时间:2017-02-01 13:49:08

标签: javascript php image file upload

在我将$_FILES["xfile1"]["tmp_name"]函数发送给move_uploaded_file()之前,有没有办法调整// Create image from file switch(strtolower($_FILES['xfile1']['type'])) { case 'image/jpeg': $image = imagecreatefromjpeg($_FILES['xfile1']['tmp_name']); break; case 'image/png': $image = imagecreatefrompng($_FILES['xfile1']['tmp_name']); break; case 'image/gif': $image = imagecreatefromgif($_FILES['xfile1']['tmp_name']); break; default: exit('Unsupported type: '.$_FILES['xfile1']['type']); } // Delete original file @unlink($_FILES['image']['tmp_name']); // Target dimensions $max_width = 540; $max_height = 540; // Get current dimensions $old_width = imagesx($image); $old_height = imagesy($image); // Calculate the scaling we need to do to fit the image inside our frame $scale = min($max_width/$old_width, $max_height/$old_height); // Get the new dimensions $new_width = ceil($scale*$old_width); $new_height = ceil($scale*$old_height); // Create new empty image $new = imagecreatetruecolor($new_width, $new_height); // Resample old into new imagecopyresampled($new, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); ob_start(); imagejpeg($new,'saved.jpeg' , 90); $data = ob_get_clean(); 的大小?我检查了所有地方,但在调整图像大小后似乎没有人使用此功能。

$data

所以到目前为止我有这个。我有$_FILES["xfile1"]["tmp_name"]变量,我想用move_uploaded_file()函数中的 localFile = open ('/home/youruser/data.bin', 'wb') try: for byteValue in arrayValue: localFile.write(chr(byteValue)) finally: localFile.close() 替换它。那可能吗? 在此先感谢。

0 个答案:

没有答案