用PHP将图像保存到服务器 [英] Saving image to server with php
本文介绍了用PHP将图像保存到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我有以下脚本,基本上是一个Flash文件向它发送一些数据并创建图像,然后为用户打开一个另存为对话框,以便他们可以将图像保存到该系统. ,如何将图像也保存到服务器上?
Hey i have the following script, basicaly a flash file sends it some data and it creates a image and then opens a save as dialog box for the user so that they can save the image to there system.Here the problem comes in, how would i go about also saving the image to my server?
<?php
$to = $_POST['to'];
$from = $_POST['from'];
$fname = $_POST['fname'];
$send = $_POST['send'];
$data = explode(",", $_POST['img']);
$width = $_POST['width'];
$height = $_POST['height'];
$image=imagecreatetruecolor( $width ,$height );
$background = imagecolorallocate( $image ,0 , 0 , 0 );
//Copy pixels
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
$int = hexdec($data[$i++]);
$color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
imagesetpixel ( $image , $x , $y , $color );
}
}
//Output image and clean
#header("Content-Disposition: attachment; filename=test.jpg" );
header("Content-type: image/jpeg");
ImageJPEG( $image );
imagedestroy( $image );
?>
我们将不胜感激!
推荐答案
imagejpeg( $image, $filename );
会将图像保存到$filename
.因此基本上可以做到
will save the image to $filename
. So essentially could do
imagejpeg( $image, $filename );
imagedestroy( $image );
readfile( $filename );
不只是打电话
imagejpeg( $image );
这篇关于用PHP将图像保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文