📄 post.php
字号:
<?php
/*--------------------------------------------------------------------
This script accepts the image data from the posted variable 'image'.
Then it decodes the image data from BASE64 form to binary array and saves it to a disk file.
Afterward it asks the applet to redirect the browser to the 'view.php'
to prove that the image is saved successfully.
---------------------------------------------------------------------*/
if (isset($_POST['image'])) {
// The script saves the image to the current directory
// with the file name suggested by the editor,
$filename = $_POST['image_name'];
// But you can use any desirable filename, for example
// create a unique filename using the current datetime
// and the user's IP address:
// $filename = time().'-'.str_replace('.','-',$_SERVER['REMOTE_ADDR']).".png";
if (is_writable("./")) { // can I write in this directory ?
if ($fp = fopen($filename,"wb")) {
// convert the image data from BASE64 to binary form
$bin_image = base64_decode($_POST['image']);
// write to the file
fwrite($fp,$bin_image);
fclose($fp);
// Redirect the browser to the 'view.php'.
// The file name and it's MIME type
// are passed to the 'view.php' as URL prameters
$filename = urlencode($filename);
$image_type = urlencode($_POST['image_type']);
echo "#SHOWDOCUMENT=view.php?filename=$filename&image_type=$image_type\n";
}
else
echo("#SHOWMESSAGE=Failed to open $filename for writing\n");
}
else
echo("#SHOWMESSAGE=post.php hasn't write permissions in this directory on the server\n");
}
else
echo("#SHOWSTATUS=Image data are not found\n");
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -