我正在创建一个网站,管理员需要在其中发布他的作品。我需要为他制作一个控制面板,以便用新内容更新网站。内容将以研究论文的形式出现,即有点像博客文章。我已经成功启用了一个界面,他可以在其中输入标题、正文和标签或关键字。
我如何创建一些东西,让他可以上传多个图像以使他的作品更具吸引力 - 即允许他在他希望显示图像的确切位置插入图像。
我查了很多资料都没有找到合适的答案
最佳答案
使用 uploadify 并将其多个参数设置为 true
<input type="file" name="file_upload" id="file_upload" />
$(function() {
$("#file_upload").uploadify({
'multi' : true,
'swf' : '/uploadify/uploadify.swf',
'uploader' : '/uploadify/uploadify.php' ,
'onUploadSuccess' : function(file, data, response) {
// Use the 'file' object to get the filename and stuff and put it somewhere on the page.
}
});
});
服务器端:
$targetFolder = '/uploads'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo $targetFolder . '/' . $_FILES['Filedata']['name'];
} else {
echo 'Invalid file type.';
}
}
关于php - 如何在 php mysql 博客中插入图像并在确切位置显示它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18452573/