What is the process for uploading JSON files through PHP code?

I have been attempting to upload a JSON file onto the server of 000webhost. Following a tutorial from w3schools (https://www.w3schools.com/php/php_file_upload.asp), I ended up removing all file checks as they were blocking JSON files. Below is the code for upload.php. I don't think it necessarily needs to be a php file, but I've tried everything I could think of.

<form action="upload_action.php" method="POST" encType="multipart/form-data">
    <input type="file" id="uploadForm" name='uploadForm'><br>
    <input class='hidden' id="submit" name="submit" type="submit" value="submit">
</form> 

And here is the code for upload_action.php:

<?php
$target_dir = "datasets/";
$target_file = $target_dir . basename($_FILES["uploadForm"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload the file
} else {
  if (move_uploaded_file($_FILES["uploadForm"]["tmp_name"], $target_file)) {
    echo "The file ". htmlspecialchars( basename( $_FILES["uploadForm"]["name"])). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}
?>

This script works perfectly with other file types that I've tested.

Answer №1

It's important to note that the uploadOk variable should be updated before checking if $uploadOk == 0. However, this issue likely isn't causing the problem with uploading. It could be possible that your file size exceeds the maximum limit allowed by the hosting service. To confirm this, try uploading a test JSON file. Additionally, ensure that there is a "tmp" directory located next to the public_html directory.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Laravel and AJAX to save multiple selected filters for future use

I've been struggling with this issue for a few weeks now and just can't seem to wrap my head around it. On my webpage, I've implemented four filters: a search filter, a year filter, a launch-site filter, and a country filter. Each of these ...

Issue with submitting forms in modal using Bootstrap

In the model box below, I am using it for login. When I click on either button, the page just reloads itself. Upon checking in Firebug, I found something like this: localhost\index.php?submit=Login <div class="modal fade" id="loginModal" tabindex= ...

Storing an object with numerical keys in MongoDB transforms it into an array

Trying to import a basic .json file: { "data": { "plans": { "1": "14", "2": "20", "3": "40" } } } After importing the json file using MongoDB Com ...

Username Availability Checker for Websites

I am attempting to develop a function that takes in a URL parameter and a username parameter. The goal is for the function to navigate to the URL, input the provided username, and then check if the page indicates that the username does not exist (error mes ...

Examine every single word and apply a filter to remove any that have fewer than x characters

In an attempt to enhance the search functionality of my FAQ, I have crafted a MySQL query as follows: $raw_results = mysql_query("SELECT * FROM faq WHERE (`question` LIKE '%".$search."%') OR (`answer` LIKE '%".$search."%')" ...

Output the distinct JSON keys in dot notation through Python

In an attempt to create a script for analyzing the structure of a JSON file efficiently, I want to print the unique keys in dot notation. Let's consider a sample file named 'myfile.json' with the format below: { "a": "one", "b": "two", "c" ...

Avoid altering URLs that are file paths

# These configuration settings direct all traffic, excluding specific files, to the dispatcher Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)$ index.php [NC,L] The issue is that it also directs specified files to the dispatcher :( Is there a ...

Is encryption functionality disabled in versions 5.6 and newer?

Having trouble encrypting passwords with this code in PHP 5.6 or later versions? I need a new code that uses the same algorithm, please advise. Could you provide me with alternative code that maintains the current encryption algorithm? <?php class Enc ...

Hey there! I'm currently facing some difficulties with storing form input data into a nested json file

I have developed a Next.js application with a form component structured as follows: components/Form.js import { useState } from 'react' import { useRouter } from 'next/router' import { mutate } from 'swr' const Form = ({ for ...

Show the result of (Firstname) on the thank you page after the form has been submitted

Need help with a PHP issue; it seems simple but I'm uncertain of the correct method, whether through jQuery or PHP. I have a contact form where I want certain field results to display on the thank you page after submitting the form: Thank you for en ...

Incorporating an Aspx Page into a Static Website

We currently have a static website consisting of all html files. In addition, we have a dynamic ASPX website with a specific page (RegisterAndBuy.aspx) that displays data based on user selections and collects personal information to send to the Admin via ...

Unable to show BLOB data stored within the database

I am facing an issue while trying to convert an image stored in blob format in my database. When I simply echo $content, the blob file is shown, indicating that there is no problem with my queries. However, the code I have only displays a broken image ins ...

Page not found: The requested file does not exist

Apache web server is claiming that the page we are attempting to reach is missing, even though we are certain it is not. It gets even more puzzling as only directory names seem to be causing issues. It's not a file permissions problem be ...

Accessing dataset schemas to parse JSON files

A JSON file has been included in a dataset within Foundry: [ { "name": "Tim", "born": "2000 01 01", "location": {"country": "UK", "city": "London"}, ...

PHP updating data in a MySQL database

I've been using easyPHP and encountering issues with updating records in my database. Whenever I try to update, the HTML form displays and instead of updating the data. However, it does print "Updated dat ...

Guide to hosting Word, Excel, PowerPoint, and PDF files on a Node.js server

I recently managed to transfer a file from my MongoDB database to my node.js server Below is a screenshot for reference: View the Screenshot here However, I am unsure of how to serve these files from the node.js server to the client side. Any help in a ...

Setting a background-image using jQuery in Codeigniter can be done by following these steps

Currently, I am developing a project in Codeigniter. In my jQuery file, I have included code to set the background image of the body element: $('body').css('background-image','url(<?php echo base_url("assets/images/bg2.png");?& ...

Revise CodeIgniter's data update operations

Greetings, I have a data array. function modifyData($id) { $sql = $this->db->query("SELECT * FROM outbound WHERE id_outbound_voice='$id' ")->result(); $data = array(); foreach ($sql as $value) { $data[] = $v ...

php resize images easily using PHP

After spending some time searching, I came across some perplexing and intricate material that I struggled to make sense of. I've been working with chronoforms in Joomla to create a form with an upload file script. The good news is that the script suc ...

"Instead of encountering a fatal error, imagine stumbling upon a blank Twig

I am facing a situation where using Twig results in a blank page instead of showing a fatal error. I understand that this is related to the error reporting settings, and I have to explicitly set it to E_ALL for it to function properly. I have implemented ...