-2

I have a php script like the following

<?php
if($_FILES['img']['type'] != "image/gif") {
    echo "<center><br>param name: img<br>directory file /challenge/ex";
    exit;
}
$uploaddir = 'ex/';
$uploadfile = $uploaddir . basename($_FILES['img']['name']);
if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "File uploading failed.\n";
}
?>
<center>
<br><br>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" size="20" name="img" />
        <input type="submit" name="upload" value="Upload" />
    </form>

but, form upload and button can't display, when i run this file

1 Answers1

0

this mostly happen when there is a php error, try to add these three lines before the second line :

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

so it will be :

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if($_FILES['img']['type'] != "image/gif") {
    echo "<center><br>param name: img<br>directory file /challenge/ex";
    exit;
}
$uploaddir = 'ex/';
$uploadfile = $uploaddir . basename($_FILES['img']['name']);
if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "File uploading failed.\n";
}
?>
<center>
<br><br>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" size="20" name="img" />
        <input type="submit" name="upload" value="Upload" />
    </form>

and hopefully some error will show up so we can fix it.