Upload script suddenly not working

BelowZero

New member
This script has worked for me for years. Suddenly I'm getting the error message when clicking the upload button.
Can anyone help?

The upload page:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p><b>Click "Choose File" button to upload a file:</b></p>
<div class="spacer"></div>
<input type="file" name="uploaded_file"></input><br />
<div class="spacer"></div>
<input type="submit" value="Upload" class="button"></input>
</form>

<FORM Method = "POST" action ="admin_main.php">
<input type="submit" name="Submit" value="Finished" class="button">
</FORM>

The upload file (upload.php):
<?PHP
if(!empty($_FILES['uploaded_file']))
{
$path = "A-Images/";
$path = $path . basename( $_FILES['uploaded_file']['name']);

if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path))
{header("Location: admin_main.php");}
else
{echo "There was an error uploading the file, please try again!";}
}

echo "The file ". basename( $_FILES['uploaded_file']['name']). " has been uploaded";
?>

I'm thinking it has to do with using a new version of PHP, but can't say for sure. I changed the version back to 7, but it still isn't working.
Any help appreciated!
 
Hi

try this


Code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

if(!empty($_FILES['uploaded_file'])) {
    $path = "A-Images/";
    $path = $path . basename($_FILES['uploaded_file']['name']);
    
    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
        header("Location: admin_main.php");
        exit; // Make sure to exit after redirecting
    } else {
        echo "There was an error uploading the file, please try again!";
    }
} else {
    echo "No file was uploaded.";
}
?>

and copy and paste the error received if anyone
 
Thanks for the reply. I actually fixed the issue by checking the file size before uploading. It seems this particular file was larger than normal and exceeded the size limit. Once I increased the limit, it worked fine. Here is the updated code:

Code:
<?PHP
$target_dir = "A-Images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}

if (file_exists($target_file)) {
  echo "Sorry, file already exists.";
  $uploadOk = 0;
}

if ($_FILES["fileToUpload"]["size"] > 10000000) {
  echo "Sorry, your file is too large.";
  $uploadOk = 0;
}

if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
  echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  $uploadOk = 0;
}

if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";

} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    header("Location: admin_main.php");
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}

?>
 
Back
Top