0

管理者が自分の作品を公開する必要があるウェブサイトを作成しています。彼がウェブサイトを新しいコンテンツで更新するためのコントロール パネルを作成する必要があります。コンテンツは研究論文の形式、つまりブログ投稿のようなものになります。タイトル、本文テキスト、タグまたはキーワードを入力できるインターフェイスを正常に有効にしました。

彼が複数の画像をアップロードして作品をより魅力的にする方法、つまり、表示したい正確な位置に画像を挿入できるものを作成するにはどうすればよいですか。

私はたくさん検索しましたが、適切な答えを見つけることができませんでした

4

1 に答える 1

0

uploadify を使用し、その multi パラメータを 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.';
    }
} 
于 2013-08-26T20:40:47.973 に答える