简体   繁体   中英

Retrieve image path from php after javascript changed src

I completely confused, I had this code

<label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
          <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?> id=<?php echo "img-hidden[".$n."]";?>>

When I click on an image, it opens an upload dialog box to choose an image to replace the given one. This Javascript code

$('#img-frm input[type="file"]').change(function(){
        // Get the input number
        var str = this.id.split("[");
        var i = str[1].substr(0,str[1].length-1);
        var s = 'img-pict[' + i + ']';
        // Get the new picture address
        var new_img = window.URL.createObjectURL(this.files[0]);
        // Preview the new picture
        document.getElementById(s).src = new_img;
        str = $(this).val().split("\\");
        var n = str.length;
        s = 'img-name[' + i + ']';
        document.getElementById(s).innerHTML = str[n-1];
    });

allows me to actually change the image I clicked on with the image I selected in the dialog box. In this code you can see I am changing the src attribute of the image tag (the lines below just display the filename under the image). Third, I have this test code

<?php print_r($_FILES); ?>

The problem is that the $_FILES array is completely empty when I click on an image, change it and submit the form. Note that the initial image was the result of a previous posted form. I thought I solved this issue two days ago but it still occurs. I need help! Here are all the codes

File 1

<?php
...

// Upload pictures
$folder = '../images/tmp';
foreach ($_FILES['files']['name'] as $i => $name){
    if (strlen($_FILES['files']['name'][$i]) > 1 && (false !== strpos($_FILES['files']['type'][$i],'image'))){
        if (!move_uploaded_file($_FILES['files']['tmp_name'][$i], $folder.'/'.$name)){
            // Redirect to the Upload form
            header('Location: osi_upload.php');
            exit();
        }
    }
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/x-icon" href="../images/favicon.ico">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="../css/preview.css">
<link rel="stylesheet" type="text/css" href="../css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="../jquery-ui-smoothness/jquery-ui.css">
<script src="../js/jquery.js"></script>
<script src="../js/bootstrap.js"></script>
<script src="../js/npm.js"></script>
<script src="../jquery-ui-smoothness/jquery-ui.js"></script>
<script src="../js/osi_jquery.js"></script>
<title>OSi, Panafrican Photographer</title>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body>
<header class="container">
    <div class="col-xs-12 col-md-2"><a href="index.php"><img src="../images/osi_logo_white.png" alt="OSi" class="img-responsive center-block"></a></div>
  <div class="text-uppercase col-xs-12 col-md-8 hide-sm">
    <div class="text-center">african international photographer</div>
  </div>
  <div class="col-md-2 hide-sm"><img src="../images/afrique.png" alt="africa_white" class="img-responsive center-block"></div>
</header>

<section class="container no-pad-left-right">
  <div class="col-xs-12 alert-info pad-top-bottom"><strong><?php echo $osi->clsdate($event_dte).' - '.$eventname_fr.': '; ?></strong><?php echo $post_fr; ?></div>
  <div class="col-xs-12 alert-info pad-top-bottom"><strong><?php echo date('M d Y', strtotime($event_dte)).' - '.$eventname_en.': '; ?></strong><?php echo $post_en; ?></div>
  <?php
    $i = -1;
  foreach(glob($folder.'/*') as $filename){
        $file[++$i] = $filename;
    } ?>

    <form action="osi_upload_confirm.php" enctype="multipart/form-data" id="img-frm" method="post"><?php
    // Medium and large devices
    switch($gallery){
        case 1:
        { ?>
            <!--Canvas 1-->
            <div class="col-xs-12 no-pad-left-right hide-sm"><?php
      for($n=0;$n<=$i;$n++){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
          <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?> id=<?php echo "img-hidden[".$n."]";?>>
        </div>
        <?php
            } ?>
            </div><?php
            break;
        }
        case 2:
        { ?>
            <!--Canvas 2-->
            <div class="col-md-3 no-pad-left-right hide-sm">
                <div class="in-block">
            <label for=<?php echo "img-input[0]"; ?>>
            <img id=<?php echo "img-pict[0]" ?> src=<?php echo "".$file[0].""; ?> class="canvas-2">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[0]"; ?>><strong><?php echo basename($file[0]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[0]"; ?> name=<?php echo "img-input[0]"; ?>>
            <input type="hidden" value=<?php echo "".$file[0].""; ?> name=<?php echo "img-hidden[0]"; ?>>
        </div>
            </div>
            <div class="col-md-9 no-pad-left-right hide-sm"><?php
      for($n=1;$n<=$i;$n++){ ?>
                <div class="in-block">
            <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div><?php
            break;
        }
        case 3:
        { ?>
            <!--Canvas 3-->
            <div class="col-md-3 no-pad-left-right hide-sm"><?php
            foreach($arr=array(0,4) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div>
      <div class="col-md-3 no-pad-left-right hide-sm">
                <div class="in-block">
            <label for=<?php echo "img-input[1]"; ?>>
            <img id=<?php echo "img-pict[1]"; ?> src=<?php echo "".$file[1].""; ?> class="canvas-2">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[1]"; ?>><strong><?php echo basename($file[1]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[1]"; ?> name=<?php echo "img-input[1]"; ?>>
            <input type="hidden" value=<?php echo "".$file[1].""; ?> name=<?php echo "img-hidden[1]"; ?>>
        </div>
            </div>
            <div class="col-md-6 no-pad-left-right hide-sm"><?php
      foreach($arr=array(2,3,5,6) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div><?php
            break;
        }
        case 4:
        { ?>
            <!--Canvas 4-->
      <div class="col-md-6 no-pad-left-right hide-sm"><?php
      foreach($arr=array(0,1,4,5) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div>
      <div class="col-md-3 no-pad-left-right hide-sm">
                <div class="in-block">
          <label for=<?php echo "img-input[2]"; ?>>
            <img id=<?php echo "img-pict[2]"; ?> src=<?php echo "".$file[2].""; ?> class="canvas-2">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[2]"; ?>><strong><?php echo basename($file[2]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[2]"; ?> name=<?php echo "img-input[2]"; ?>>
            <input type="hidden" value=<?php echo "".$file[2].""; ?> name=<?php echo "img-hidden[2]"; ?>>
        </div>
            </div>
            <div class="col-md-3 no-pad-left-right hide-sm"><?php
            foreach($arr=array(3,6) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div><?php
            break;
        }
        case 5:
        { ?>
            <!--Canvas 5-->
            <div class="col-md-9 no-pad-left-right hide-sm"><?php
      foreach($arr=array(0,1,2,4,5,6) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div>
            <div class="col-md-3 no-pad-left-right hide-sm">
                <div class="in-block">
          <label for=<?php echo "img-input[3]"; ?>>
            <img id=<?php echo "img-pict[3]"; ?> src=<?php echo "".$file[3].""; ?> class="canvas-2">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[3]"; ?>><strong><?php echo basename($file[3]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[3]"; ?> name=<?php echo "img-input[3]"; ?>>
            <input type="hidden" value=<?php echo "".$file[3].""; ?> name=<?php echo "img-hidden[3]"; ?>>
        </div>
            </div><?php
            break;
        }
        case 6:
            { ?>
            <!--Canvas 6-->
      <div class="col-md-3 no-pad-left-right hide-sm">
                <div class="in-block">
          <label for=<?php echo "img-input[0]"; ?>>
            <img id=<?php echo "img-pict[0]"; ?> src=<?php echo "".$file[0].""; ?> class="canvas-2">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[0]"; ?>><strong><?php echo basename($file[0]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[0]"; ?> name=<?php echo "img-input[0]"; ?>>
            <input type="hidden" value=<?php echo "".$file[0].""; ?> name=<?php echo "img-hidden[0]"; ?>>
        </div>
            </div>
      <div class="col-md-3 no-pad-left-right hide-sm"><?php
            foreach($arr=array(1,4) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div>
      <div class="col-md-3 no-pad-left-right hide-sm">
                <div class="in-block">
          <label for=<?php echo "img-input[2]"; ?>>
            <img id=<?php echo "img-pict[2]"; ?> src=<?php echo "".$file[2].""; ?> class="canvas-2">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[2]"; ?>><strong><?php echo basename($file[2]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[2]"; ?> name=<?php echo "img-input[2]"; ?>>
            <input type="hidden" value=<?php echo "".$file[2].""; ?> name=<?php echo "img-hidden[2]"; ?>>
        </div>
            </div>
      <div class="col-md-3 no-pad-left-right hide-sm"><?php
            foreach($arr=array(3,5) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
        <?php
            } ?>
            </div><?php
                break;
            }
            case 7:
            { ?>
        <!--Canvas 7-->
        <div class="col-md-3 no-pad-left-right hide-sm"><?php
        foreach($arr=array(0,4) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
          <?php
        } ?>
        </div>
        <div class="col-md-3 no-pad-left-right hide-sm">
          <div class="in-block">
            <label for=<?php echo "img-input[1]"; ?>>
              <img id=<?php echo "img-pict[1]"; ?> src=<?php echo "".$file[1].""; ?> class="canvas-2">
              <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[1]"; ?>><strong><?php echo basename($file[1]); ?></strong></div>
            </label>
            <input type="file" id=<?php echo "img-input[1]"; ?> name=<?php echo "img-input[1]"; ?>>
            <input type="hidden" value=<?php echo "".$file[1].""; ?> name=<?php echo "img-hidden[1]"; ?>>
          </div>
        </div>
        <div class="col-md-3 no-pad-left-right hide-sm"><?php
        foreach($arr=array(2,5) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
          <?php
        } ?>
        </div>
        <div class="col-md-3 no-pad-left-right hide-sm">
          <div class="in-block">
            <label for=<?php echo "img-input[3]"; ?>>
              <img id=<?php echo "img-pict[3]"; ?> src=<?php echo "".$file[3].""; ?> class="canvas-2">
              <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[3]"; ?>><strong><?php echo basename($file[3]); ?></strong></div>
            </label>
            <input type="file" id=<?php echo "img-input[3]"; ?> name=<?php echo "img-input[3]"; ?>>
            <input type="hidden" value=<?php echo "".$file[3].""; ?> name=<?php echo "img-hidden[3]"; ?>>
          </div>
        </div><?php
                break;
            }
            case 8:
            { ?>
        <!--Canvas 8-->
        <div class="col-md-3 no-pad-left-right hide-sm"><?php
        foreach($arr=array(0,4) as $n){ ?>
                <div class="in-block">
          <label for=<?php echo "img-input[".$n."]"; ?>>
            <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
            <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
          </label>
          <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
        </div>
          <?php
        } ?>
        </div><?php
        foreach($arr=array(1,2,3) as $n){ ?>
          <div class="col-md-3 no-pad-left-right hide-sm">
            <div class="in-block">
              <label for=<?php echo "img-input[".$n."]"; ?>>
                <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-2">
                <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
              </label>
              <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
              <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
            </div>
          </div><?php
        }
                break;
            }
            case 9:
            { ?>
        <!--Canvas 9-->
        <div class="col-xs-12 no-pad-left-right hide-sm"><?php
        for($n=0;$n<=$i;$n++){ ?>
          <div class="in-block">
            <label for=<?php echo "img-input[".$n."]"; ?>>
              <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-2">
              <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
            </label>
            <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
            <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
          </div>
          <?php
        } ?>
        </div><?php
                break;
            }
    } ?>

  <!--Extra small and small devices-->
  <div class="col-xs-12 no-pad-left-right hide-md"><?php
  for($n=0;$n<=$i;$n++){ ?>
    <div class="in-block">
      <label for=<?php echo "img-input[".$n."]"; ?>>
        <img id=<?php echo "img-pict[".$n."]"; ?> src=<?php echo "".$file[$n].""; ?> class="canvas-1">
        <div class="alert-success pad-top-bottom text-center" id=<?php echo "img-name[".$n."]"; ?>><strong><?php echo basename($file[$n]); ?></strong></div>
      </label>
      <input type="file" id=<?php echo "img-input[".$n."]"; ?> name=<?php echo "img-input[".$n."]"; ?>>
      <input type="hidden" value=<?php echo "".$file[$n].""; ?> name=<?php echo "img-hidden[".$n."]"; ?>>
    </div>
    <?php
  } ?>
  </div>

  <!--Updating form-->
  <div class="col-xs-12 pad-top-bottom"></div>
  <div class="form-group col-xs-12 col-md-6">
    <label>Name of the new portfolio</label>
    <input type="text" class="form-control input-sm" name="eventname_en" value=<?php echo "'".$eventname_en."'"; ?> required>
  </div>
  <div class="form-group col-xs-12 col-md-6">
    <label>Nom du nouvel album</label>
    <input type="text" class="form-control input-sm" name="eventname_fr" value=<?php echo "'".$eventname_fr."'"; ?> required>
  </div>
  <div class="form-group col-xs-12">
    <label>Artist name/Nom de l'artiste</label>
    <input type="text" class="form-control input-sm" name="artist" value=<?php echo "'".$artist."'"; ?> required>
  </div>
  <div class="form-group col-xs-12 col-md-6">
    <label>Write the presentation text</label>
    <textarea cols="53" rows="10" name="post_en" class="form-control form-except input-sm" required><?php echo $post_en; ?></textarea>
  </div>
  <div class="form-group col-xs-12 col-md-6">
    <label>Entrer le texte de présentation</label>
    <textarea cols="53" rows="10" name="post_fr" class="form-control form-except input-sm" required><?php echo $post_fr ?></textarea>
  </div>
  <div class="form-group col-xs-12">
    <label>Select the gallery type/Selectionner le type de galérie</label>
      <select name="gallery" class="form-control input-sm" required><?php
            $n = $i + 1;
            switch($n){
                case 4:
                { ?>
          <option value="0" <?php if($gallery==0) echo 'selected'; ?>>Gallery intro</option>
          <option value="1" <?php if($gallery==1) echo 'selected'; ?>>Gallery type 01</option>
          <option value="2" <?php if($gallery==2) echo 'selected'; ?>>Gallery type 02</option>
          <option value="3" <?php if($gallery==3) echo 'selected'; ?>>Gallery type 03</option>
          <option value="4" <?php if($gallery==4) echo 'selected'; ?>>Gallery type 04</option>
          <option value="5" <?php if($gallery==5) echo 'selected'; ?>>Gallery type 05</option>
          <option value="6" <?php if($gallery==6) echo 'selected'; ?>>Gallery type 06</option>
          <option value="7" <?php if($gallery==7) echo 'selected'; ?>>Gallery type 07</option>
          <option value="8" <?php if($gallery==8) echo 'selected'; ?>>Gallery type 08</option>
          <option value="9" <?php if($gallery==9) echo 'selected'; ?>>Gallery type 09</option><?php
                    break;
                }
                case 5:
                { ?>
          <option value="1" <?php if($gallery==1) echo 'selected'; ?>>Gallery type 01</option>
          <option value="2" <?php if($gallery==2) echo 'selected'; ?>>Gallery type 02</option>
          <option value="3" <?php if($gallery==3) echo 'selected'; ?>>Gallery type 03</option>
          <option value="4" <?php if($gallery==4) echo 'selected'; ?>>Gallery type 04</option>
          <option value="5" <?php if($gallery==5) echo 'selected'; ?>>Gallery type 05</option>
          <option value="6" <?php if($gallery==6) echo 'selected'; ?>>Gallery type 06</option>
          <option value="7" <?php if($gallery==7) echo 'selected'; ?>>Gallery type 07</option>
          <option value="8" <?php if($gallery==8) echo 'selected'; ?>>Gallery type 08</option><?php
                    break;
                }
                case 6:
                { ?>
          <option value="1" <?php if($gallery==1) echo 'selected'; ?>>Gallery type 01</option>
          <option value="2" <?php if($gallery==2) echo 'selected'; ?>>Gallery type 02</option>
          <option value="3" <?php if($gallery==3) echo 'selected'; ?>>Gallery type 03</option>
          <option value="4" <?php if($gallery==4) echo 'selected'; ?>>Gallery type 04</option>
          <option value="5" <?php if($gallery==5) echo 'selected'; ?>>Gallery type 05</option>
          <option value="6" <?php if($gallery==6) echo 'selected'; ?>>Gallery type 06</option>
          <option value="7" <?php if($gallery==7) echo 'selected'; ?>>Gallery type 07</option><?php
                    break;
                }
                case 7:
                { ?>
          <option value="1" <?php if($gallery==1) echo 'selected'; ?>>Gallery type 01</option>
          <option value="2" <?php if($gallery==2) echo 'selected'; ?>>Gallery type 02</option>
          <option value="3" <?php if($gallery==3) echo 'selected'; ?>>Gallery type 03</option>
          <option value="4" <?php if($gallery==4) echo 'selected'; ?>>Gallery type 04</option>
          <option value="5" <?php if($gallery==5) echo 'selected'; ?>>Gallery type 05</option><?php
                    break;
                }
                case 8:
                { ?>
          <option value="1" <?php if($gallery==1) echo 'selected'; ?>>Gallery type 01</option><?php
                    break;
                }
            } ?>
    </select>
  </div>
  <div class="form-group col-xs-12">
    <label>Name of the City/Nom de la ville</label>
    <input type="text" class="form-control input-sm" name="city" value=<?php echo "'".$city."'"; ?> required>
  </div>
  <div class="form-group col-xs-12">
    <label>Date de l'évènement/Event date</label>
    <input type="date" class="form-control input-sm" name="event_dte" value=<?php echo "'".$event_dte."'"; ?> required>
    <input type="hidden" name="photoid" value=<?php echo "'".$photoid."'"; ?>>
  </div>
  <div class="pull-right"><a href="osi_upload.php" class="btn btn-danger">Cancel</a> <button type="submit" class="btn btn-success">Submit</button></div>
    </form>
</section>
</body>

</html>

File 2

// JavaScript Document
$(document).ready(function(){       
    // Change clicked pictures
    if(!$('#img-frm input[type="file"]')){
        return;
    }
    $('#img-frm input[type="file"]').change(function(){
        // Get the input number
        var str = this.id.split("[");
        var i = str[1].substr(0,str[1].length-1);
        var s = 'img-pict[' + i + ']';
        // Get the new picture address
        var new_img = window.URL.createObjectURL(this.files[0]);
        // Preview the new picture
        document.getElementById(s).src = new_img;
        str = $(this).val().split("\\");
        var n = str.length;
        s = 'img-name[' + i + ']';
        document.getElementById(s).innerHTML = str[n-1];
    });
});

File 3

<?php
// Test $_FILES array
print_r($_FILES);
?>

I can't see where I messed up, the src attribute of the image change with Javascript but the form post an empty $_FILES array .

After making some tests, I realized that the issue comes from the HTML form that doesn't send the $_FILES data.

First, the <!---Extra small and small devices---> code overwrites the //Medium and large device data because they had the same variables names, I made the variables names distinct.

Second, There are too many successive divs . It seems to cause a breach in the form, I not sure to understand why? But I had no data with those successive divs (or maybe I didn't saw the actual issue there). But I changed the layout of my divs and now my form works perfectly.

So, two issues: the php variables names and the divs layouts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM