2

基本的なセットアップで、uploadifyスクリプトを実行しています。画像の宛先フォルダーをハードコーディングすると正常に機能しますuploadify.php-今、そのフォルダーを動的にしたいと思います。どうすればいいですか?

$uploadify_path必要なフォルダーへのパスを含むPHP 変数があります。uploadify.php と check_exists.php の両方でハードコーディングされたものを切り替えました$targetPath = path/to/directory$targetPath = $uploadify_path、機能しません。ファイルのアップロード アニメーションが実行され、完了したことが示されますが、ディレクトリは空のままです。ファイルはどこかに隠れていません。

Javascript にフォルダを指定するオプションがあるようです。私もこれを試しましたが、役に立ちませんでした。

この変数の宛先をアップロードする方法を誰かが教えてくれたら、とても感謝しています。

チェック用に現在のコードを含めます(基本的にデフォルト):

Javascript

<script type="text/javascript">
$(function() {

    $('#file_upload').uploadify({
        'swf'      : 'uploadify/uploadify.swf',
        'uploader' : 'uploadify/uploadify.php',
        // Put your options here
    });
});
</script>

uploadify.php

$targetPath = $_SERVER['DOCUMENT_ROOT'] . $uploadify_path; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetFile = $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 '1';
    } else {
        echo 'Invalid file type.';
    }
}
4

1 に答える 1

4

JS

<script type="text/javascript">
    $(function() {

        $('#file_upload').uploadify({
            'formData' : {'path':'/file/path'},
            'swf'      : 'uploadify/uploadify.swf',
            'uploader' : 'uploadify/uploadify.php'
            // Put your options here
        });
    });
</script>

PHP

$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_POST['path']; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetFile = $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 '1';
    } else {
        echo 'Invalid file type.';
    }
}
于 2012-07-10T03:13:27.527 に答える