我有一个函数,可以用PHP写服务器文件夹上的图像。我遵循这个链接Can't save a HTML5 Canvas as Image on a server指示,我的问题是,我想显示图像保存时的成功消息。在我的代码上,它只是在写入映像失败时才显示消息。这里是我的功能:如何在php上写文件后显示消息成功?
$loc = $_POST['lokasi'];
define('UPLOAD_DIR', $loc);
$filename = $_POST['nama-file'];
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR ;
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';
感谢您的回应。 :)
是否文件成功上传? $ loc是可访问和可写的吗? – Raptor
是的,文件上传成功,但没有显示成功消息? –
它是安全的吗?当用户可以直接在服务器文件夹上写入图像? –