PHP将图像保存到服务器?
我有一些PHP的残端...PHP将图像保存到服务器?
我有一个Flash应用程序发送图像(使用as3corelib)到一个PHP脚本,它在浏览器中预览它,它的工作!但是,我实际上喜欢将其永久保存在服务器文件夹中(上传等),而不是暂时保存它。我无法在PHP中找到实际将图像发送到服务器的正确变量,以便将其保存起来。
<?php
switch ($_POST["format"]) {
case 'jpg':
header('Content-Type: image/jpeg');
break;
case 'png':
header('Content-Type: image/png');
break;
}
if ($_POST['action'] == 'prompt') {
header("Content-Disposition: attachment; filename=" . $_POST['fileName']);
}
echo base64_decode($_POST["image"]);
?>
下面是它的一个例子:http://shmoggo.com/snapshot JPEG,开放的浏览器(但我想它保存到浏览器)
任何PHP大师帮助将是了不起的,非常感谢!
亚伦
如果你有文件名,你可以简单地做
$newpath = "/folders/image.jpg";
$data = file_get_contents($_POST['fileName']);
file_put_contents($newpath, $data);
谢谢!这看起来很完美,但我无法让它为我的生活工作!它保存了一个空白的“image.jpg”没有数据......任何想法? – Aaron 2012-01-07 20:39:53
是$ _POST ['fileName']远程服务器上的图像的实际文件名,而不是一些本地路径吗?也许如果$ _POST [“image”]已经有了实际的数据,那么你可以使用file_put_contents作为数据...你可能需要base64_decode。 – hackartist 2012-01-07 21:37:46
通常PHP存储上传文件数据在$ _FILES中,请尝试var_dump($ _ FILES)以查看它是否包含数据。 [php上传](http://www.php.net/manual/en/features.file-upload.post-method.php) – 2012-01-07 20:09:44
@DipuRaj感谢您的评论,它帮助了很多。 – Aaron 2012-01-08 03:37:39