John Davidson

php - files not being posted into $_FILES super global array

0 comments
Message:


I am having trouble with a file upload portion of a project. I have created the form with the inputs but when i try to "upload" the file it does not get posted into the $_FILES array. Code posted below. I have declared an enctype within the from tag but the file still does not get posted into the array it only shows Array()


here is my form code:


<?php

require("includes/application_top.php");
$pageTitle = "Add A Product";
require("includes/header.php");
print_r($_FILES);

?>
<div class="container-fluid py-4">

<div class="row ">
<div class="col">
<form method="POST" action="s.php" enctype="multipart/form-data">
<!-- Product Name input -->
<div class="form-outline">
<input type="text" id="ProductName" class="form-control" />
<label class="form-label" for="ProductName"> Product Name</label>
</div>
</div>
<div class="col">
<!-- Product Description input -->
<div class="form-outline">
<input type="text" id="ProductDesc" class="form-control" />
<label class="form-label" for="ProductDesc">Product Description</label>
</div>
</div>
</div>

<hr />

<div class="row">
<div class="col">
<!-- Product Price input -->
<div class="form-outline">
<input type="number" min="0.00" max="10000.00" step="0.01" id="ProductPrice" class="form-control" />
<label class="form-label" for="ProductPrice">Product Price </label>
</div>
</div>
<div class="col">
<!-- Img Upload input -->
<div class="form-outline input-group mb-3 ">
<input type="file" id="ImageUpload" class="form-control" />

<input type="submit" value="Upload" />
</div>
</div>
</div>
</form>
</div>
<?php
require("includes/footer.php")
?>


My Answer:
upload a file, it is not being posted into the $_FILES super global array.

There are a few common reasons why this might be happening:

1. Make sure that the form tag has the enctype attribute set to "multipart/form-data". This is necessary for file uploads to work properly.

2. Check that the file input field in the form has the name attribute set correctly. The name attribute should match the key in the $_FILES super global array where the file will be stored.

3. Verify that the file being uploaded is not too large. There is a limit on the size of files that can be uploaded, which is set in the php.ini file. You can adjust this limit by changing the upload_max_filesize and post_max_size directives in the php.ini file.

4. Check the file upload directory permissions. The directory where the files are being uploaded to should have the correct permissions set to allow files to be uploaded.

If you have checked all of these things and are still having trouble, you may want to try using a file upload library or framework that handles file uploads more robustly.

Rate this post

3 of 5 based on 5404 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us