簡體   English   中英

將PNG上傳到網站服務器

[英]Uploading PNG to Website Server

我看到了很多其他主題,並且都嘗試了全部。 有人可以幫忙為什么這個腳本不能上傳PNG文件嗎? 正在顯示空白的PNG圖像。

$image = $_FILES['file']['tmp_name'];
$image_name = $_FILES['file']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);

$location = "Profiles/{$user}/Picture/{$image_name}";

$new_image = imagecreatetruecolor(100, 100);

$source_image = imagecreatefrompng($image);

imagealphablending($source_image, false);
imagesavealpha($source_image, true);
imagealphablending($new_image, false);
imagesavealpha($new_image, true);

imagecopyresampled($new_image, $image, 0, 0, 0, 0, 100, 100, $image_width, $image_height);

imagepng($new_image, '../' . $location, 9);

您沒有聲明$image_width$image-height ,而是在imagecopyresampled()中引用$image而不是$source_image

我也得到了純白色的圖像,但是在此之后,我得到了預期的結果:

$image = $_FILES['file']['tmp_name'];
$image_name = $_FILES['file']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);

$location = "Profiles/{$user}/Picture/{$image_name}";

$new_image = imagecreatetruecolor(100, 100);

$source_image = imagecreatefrompng($image);

// Get the width & height of the uploaded image.
$image_width = imagesx($source_image);
$image_height = imagesy($source_image);

imagealphablending($source_image, false);
imagesavealpha($source_image, true);
imagealphablending($new_image, false);
imagesavealpha($new_image, true);

imagecopyresampled($new_image, $source_image, 0, 0, 0, 0, 100, 100, $image_width, $image_height);

imagepng($new_image, '../' . $location, 9);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM