Skip to main content
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
edited tags
Link
Brythan
  • 7k
  • 3
  • 22
  • 37
added 3 characters in body; edited tags
Source Link
Phrancis
  • 20.5k
  • 6
  • 70
  • 155

I literally spend my all day working on PHP and I think I figured it out, but I need some reviews in order to make my code secure & okay. I am asking you about functionality here. The code below works.

index###index.php

<form action="upload.php" method="post" enctype="multipart/form-data">
    <div id="file_container">
        <input name="images[]" multiple type="file" id="file[]"/><br/>
        <input type="submit">
    </div>
</form>

upload###upload.php

$target = "upload/";

$uploadit = 1; // I will change it with extension checker.
$checksize = // will check file size

foreach($_FILES['images']['name'] as $key => $value){
    $path = $_FILES['images']['name'][$key];
    $ext = pathinfo($path, PATHINFO_EXTENSION);

    $name = md5($name);
    $generate1 = md5(date('Y-m-d H:i:s:u'));
    $randomizer = uniqid($name);
    $name = $name . $generate1 . $randomizer;
        if ($uploadit == 1) {
               if (move_uploaded_file($_FILES['images']['tmp_name'][$key], $target.$name.".".$ext)){
                echo "<strong>".$value ."</strong>Your files have been upload successfully<br />\n";
            }
        } else {
            echo "Failed";
        }

I literally spend my all day working on PHP and I think I figured it out, but I need some reviews in order to make my code secure & okay. I am asking you about functionality here. The code below works.

index.php

<form action="upload.php" method="post" enctype="multipart/form-data">
    <div id="file_container">
        <input name="images[]" multiple type="file" id="file[]"/><br/>
        <input type="submit">
    </div>
</form>

upload.php

$target = "upload/";

$uploadit = 1; // I will change it with extension checker.
$checksize = // will check file size

foreach($_FILES['images']['name'] as $key => $value){
    $path = $_FILES['images']['name'][$key];
    $ext = pathinfo($path, PATHINFO_EXTENSION);

    $name = md5($name);
    $generate1 = md5(date('Y-m-d H:i:s:u'));
    $randomizer = uniqid($name);
    $name = $name . $generate1 . $randomizer;
        if ($uploadit == 1) {
               if (move_uploaded_file($_FILES['images']['tmp_name'][$key], $target.$name.".".$ext)){
                echo "<strong>".$value ."</strong>Your files have been upload successfully<br />\n";
            }
        } else {
            echo "Failed";
        }

I literally spend all day working on PHP and I think I figured it out, but I need some reviews in order to make my code secure & okay. I am asking you about functionality here. The code below works.

###index.php

<form action="upload.php" method="post" enctype="multipart/form-data">
    <div id="file_container">
        <input name="images[]" multiple type="file" id="file[]"/><br/>
        <input type="submit">
    </div>
</form>

###upload.php

$target = "upload/";

$uploadit = 1; // I will change it with extension checker.
$checksize = // will check file size

foreach($_FILES['images']['name'] as $key => $value){
    $path = $_FILES['images']['name'][$key];
    $ext = pathinfo($path, PATHINFO_EXTENSION);

    $name = md5($name);
    $generate1 = md5(date('Y-m-d H:i:s:u'));
    $randomizer = uniqid($name);
    $name = $name . $generate1 . $randomizer;
        if ($uploadit == 1) {
               if (move_uploaded_file($_FILES['images']['tmp_name'][$key], $target.$name.".".$ext)){
                echo "<strong>".$value ."</strong>Your files have been upload successfully<br />\n";
            }
        } else {
            echo "Failed";
        }
Source Link
salep
  • 185
  • 1
  • 1
  • 5
Loading