Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/php/forward/upload_comp/upload_comp.php on line 29

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/7.4/lib/php') in /home/users/2/moriya-h5/web/confrage/php/forward/upload_comp/upload_comp.php on line 29
 
トップページ >  PHP >  ファイルアップロード(複数)
初版2008/11/20: 最終更新日2008/11/20
ファイルアップロード(複数)
目次
ファイルアップロード(複数)
サンプルコード
サンプル
ファイルアップロード(複数)
複数のファイルをまとめてアップロードする方法を説明します。

<input>タグ(type属性:file)のname属性を配列にすると、
一度に複数のファイルをアップロードできます。
単独でのファイルアップロード方法については こちら を御覧下さい。

以下が簡単なサンプルになります。

サンプルコード
(php部)
<?php
// 実行ボタンが押された時
if (isset($_POST[btnExec])) {
    //3回アップロードを行うので、処理の分だけループする。
    for ($i = 0; $i < 3; $i++) {
        // ファイルの転送先を設定します。
        // ファイルパス(絶対パス、ファイル名まで含む)を指定します。
        // また、転送先はパーミッションの書き込み権限を許可してください。
        $movetofile = "fullpath/" . $_FILES[uploadfile][name][$i];
        // テンポラリファイルを正規の場所に移動します。
        move_uploaded_file( $_FILES[uploadfile][tmp_name][$i], $movetofile );
    }
}
?>
(html部)
<form method="post" enctype="multipart/form-data">
    <input type="file" name="uploadfile[]" size="75">
    <input type="file" name="uploadfile[]" size="75">
    <input type="file" name="uploadfile[]" size="75">
    <input type="submit" name="btnExec" value="実行">
</form>
サンプル

「参照」ボタンでファイルを選択し、「実行」ボタンでアップロードを行う。







Warning: Use of undefined constant btnExec - assumed 'btnExec' (this will throw an Error in a future version of PHP) in /home/users/2/moriya-h5/web/confrage/php/forward/upload_comp/upload_comp.php on line 116

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/php/forward/upload_comp/upload_comp.php on line 131

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/7.4/lib/php') in /home/users/2/moriya-h5/web/confrage/php/forward/upload_comp/upload_comp.php on line 131