【问题标题】:how to insert images in a php mysql blog and display them at exact position如何在 php mysql 博客中插入图像并在确切位置显示它们
【发布时间】:2013-08-26 20:35:13
【问题描述】:

我正在创建一个网站,管理员需要在其中发布他的作品。我需要为他制作一个控制面板,以便用新内容更新网站。内容将采用研究论文的形式,即有点像博客文章。我已经成功启用了一个界面,他可以在其中输入标题、正文和标签或关键字。

我如何创建一些东西,让他可以上传多张图片以使他的作品更具吸引力 - 即允许他将图片插入到他希望显示它们的确切位置。

我搜索了很多,但找不到合适的答案

【问题讨论】:

    标签: php mysql image blogs


    【解决方案1】:

    使用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.';
        }
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-28
      • 2011-12-11
      • 2019-04-22
      • 1970-01-01
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多