Questions tagged [file]

A repository for diverse and valuable data, accessed through a textual name or route. These files offer computer applications the ability to access information consistently stored in various mediums.

How to Remove a File with a PHP Link

I am in the process of creating an intranet customer management system that will be run on a standalone computer. The software will allow the staff at the shop to upload files to each customer's record. When a customer's record is accessed, all the content ...

Fetch a document from a NodeJS Server utilizing Express

Is there a way to download a file from my server to my machine by accessing a page on a nodeJS server? I am currently using ExpressJS and I have attempted the following: app.get('/download', function(req, res){ var file = fs.readFileSync(__dirname + ' ...

Incorporate a binary document into a JSPdf file

I am currently utilizing JsPDF to export HTML content into a downloadable PDF. Explore the following example which involves taking some HTML content and generating a downloaded PDF file using JsPdf import React from "react"; import { render } fro ...

Retrieve a list of files that match a specific pattern in PHP and organize them based on the oldest file

Suppose there is a directory with the following list of files: Something_2015020820.txt something_5294032944.txt.a something_2015324234.txt Something_2014435353.txt.a The goal is to retrieve a list of files sorted by the oldest date (not filename) and on ...

PHP - Change the names of all files within a directory to 1.ext, 2.ext, 3.ext

...and by .ext, I'm referring to maintaining the original file extension! This question has been raised in the past, but unfortunately, the solution provided doesn't seem to work at all. At least not for me. Here is how I began: $directory = $_SERVER['D ...

Is there a way to read and write data in memory in Python similar to how one would with a file?

My background is in C++, and I typically create data handling classes/functions to work with stream objects instead of files. I'm curious about how I could revise the following code to handle a stream of binary data in memory rather than a file handle. de ...

Display all the files in a specified directory using Python3

What is the best way to display only file names from a specific directory without including any sub-directory files? ...

Error in creating object URL: `argument must be a Blob instance. Received an instance of Blob`

Within my express route, I have the following code snippet: let response = await fetch("http://someurl"); response = await response.blob(); console.log(response) const imgURL = URL.createObjectURL(response); However, I am encountering an error a ...

What causes a folder to disappear after rerunning in nest.js?

When working on my project using nest.js in MacOS Sonoma, I encountered a problem where the image folder src/products/images gets deleted after every project rerun (npm start). The images are saved like this: for (const image of images) { const fileName ...

Saving a local JSON file in Angular 5 using Typescript

I am currently working on developing a local app for personal use, and I want to store all data locally in JSON format. I have created a Posts Interface and an array with the following data structure: this.p = [{ posts:{ id: 'hey man', ...

Python error: "IndexError: the index of the string is beyond the specified range"

After importing my txt file as a string using the `open` method: with open('./doc', 'r') as f: data = f.readlines() I then attempted to clean the data by iterating through it with a for loop: documents = [] for line in data: ...

When using PHP, JavaScript, and HTML, you can trigger an image upload immediately after choosing a file using the

I currently have a small form with two buttons - one for browsing and another for uploading an image. I feel that having two separate buttons for this purpose is unnecessary. Is there a way to combine the browse and upload functions into just one button? ...

Guide on transferring CSV files from a different server to my server via an FTP connection

Hey there, I'm trying to figure out how to download CSV files from a folder located on the root directory of one server to another server using FTP connection. I've included the code below, but unfortunately it's not working for me. The FTP connection is ...

Export Page Elements from Selenium to a File

I've created a script using Selenium IDE for Firefox on Windows 7 with FF 25.01 IDE version 2.4.0. The script is functioning well, but I'm interested in saving a particular page element from the query it executes to a text file. The page being l ...

Alert: The function imagecolorallocate() requires the first parameter to be a resource, but a boolean was provided

Encountering errors when customers attempt to upload a jpg image on my PrestaShop front office product page: Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in /var/www/peciatky/eshop/images.inc.php on line 255 Warning: im ...

Deleting all JSON files in a directory using NodeJs

Is there a way to delete only the json files within a directory (multiple levels) without specifying each file name individually? I thought fs-unlinkSync(path) might work, but I haven't found that solution yet. I attempted to use the following method: fs. ...

Restrictions on File Size in Express Server (Exceeding 50MB)

Is there a method to upload files larger than 50 mb on the express server? I keep encountering the file size limitation of 50 mb. Appreciate any help. Thank you. ...

Is there a way to display and output the data from a file?

I'm currently working on a program that opens a file and displays its contents. I'm running into issues with defining it, I think? Either I get an error saying "path" is not defined or "new_dir" is not defined. Below is the code: import pathlib def prog_ ...

adding a collection of file names from a directory into a mysql database

I have a task where I need to fetch a list of filenames from a folder and then insert them into a mysql database using php. However, when I try inserting the filenames into the database, it seems to be stuck in an infinite loop. Even though there are only ...

Searching for a particular line within a file: What's the best method?

I have the following content in a text file: 1 /run/media/dsankhla/Entertainment/English songs/Apologise (Feat. One Republic).mp3 3 /run/media/dsankhla/Entertainment/English songs/Bad Meets Evil.mp3 5 /run/media/dsankhla/Entertainment/English songs/Love M ...

transforming log data from JSON format into individual columns, resulting in a separate file for each column

Here is an example from a log file: {"timestamp": "2022-01-14T00:12:21.000", "Field1": 10, "Field_Doc": {"f1": 0}} {"timestamp": "2022-01-18T00:15:51.000", "Field_Doc": {"f ...

The filesize() function consistently returns 0 bytes, despite the fact that the actual file size is not 0 bytes

I have written some code below and I am currently testing it, so there are no database queries in the code yet. In the code below, where it checks if(filesize($filename) != 0), it always goes to the else block even though the file is not empty and has 16 ...

The process of adding new files to an event's index

I'm trying to attach a file to an event like this: event.target.files[0]=newFile; The error I'm getting is "Failed to set an indexed property on 'FileList': Index property setter is not supported." Is there an alternative solution for this issue? ...

Converting Blob to File in Electron: A step-by-step guide

Is there a way to convert a Blob into a File object in ElectronJS? I attempted the following: return new File([blob], fileName, {lastModified: new Date().getTime(), type: blob.type}); However, it appears that ElectronJs handles the File object differently ...

Using JavaScript to dynamically alter the background image of an HTML document from a selection of filenames

Just starting out with JavaScript and working on a simple project. My goal is to have the background image of an HTML document change to a random picture from a directory named 'Background' every time the page is opened. function main() { // ...

A dynamic jQuery approach for uploading multiple files on the fly

I am working on a project that involves uploading images through a form. I am unsure of the exact number of pictures that will need to be uploaded at one time. Is there a solution using jQuery/AJAX to add file upload fields dynamically to the form? ...

Locate a specific condition within my document and display the entire row using Python

def novice(): dataFile = "studentgrades.csv" fileData = open(dataFile, "r") userScores = [] if "novice" in row print (row) fileData.close() I have attempted to write this function but I'm unsure ...

Saving output to a document. [Programming in Python]

I have successfully completed a task given by my teacher to generate attributes for a user based on their name. I used Json to write the data to a file and managed to do it with just 'math' and 'random', as per the requirements. However ...

Methods for verifying if a file is included in another file, while disregarding any whitespace adjustments

Let's say I have multiple CSS files (a.css, b.css, ..., e.css) and after concatenating and compressing them, I get a new file called compressed.css. Now, I need to verify if each of the original CSS files is included in the compressed.css file. Are th ...

Can you explain to me the file format that displays as b'x1fx8b...'?

Upon receiving a file from aws s3, it appears in the following format: b'x1fx8bx08x00x0e@xfd[x00x03x03x00x00x00x00x00x00x00x00' What exactly does this represent? In addition, when extracting data, unzipping, and uploading it back to aws ...

Node.js user attempting to upload and handle files without any external libraries, solely relying on traditional JavaScript and HTML techniques

Previously, my Node.js code seamlessly integrated with any javascript+HTML project I worked on, leading me to believe there was a direct correlation between Node.js and vanilla Javascript+HTML. However, this misconception was shattered when attempting to u ...

Only updating a file if its contents differ from the data being written

Here is a code snippet I'm looking for: fs.writeFile(fullFileAddress , data, function (err) { if(err) { if(err.code == 'ENOENT') { console.error( new Error(`#Space. Can not save file. message: ${err}`.red ...

Sending a Content-Length header with a file response in Laravel is not supported

I am currently attempting to include the Content-Length header in my file response in order to display a progress bar on the client side. I am using this method: return response()->header('Content-Length', $fileSize)->file($this->filesPa ...

Creating an HTML form that submits data to a PHP script, which then saves the

Looking for some assistance with a PHP issue I am having. I know my way around PHP, but I wouldn't say I'm an expert. Here's the problem: I have created an HTML form (form.html) and now I want the output from formular.php to be saved as a unique HTML file ...

How can PHP retrieve data from a text file that has been uploaded?

Is it feasible to display the contents of a text file uploaded via a form directly from the $_FILES variable without saving it on the server first? I am aware of the security implications, but this will only be executed on a local machine. ...

Utilizing AJAX for sending a data string and image file to a PHP server

Is it possible to include an image file in the dataString for a single function? Here is what I have: $.ajax({ type: "POST", url: "../insert.php", data: dataString, success: function(response){ console.log( ...

What is the process for storing public and private keys in a file with node.js crypto?

I am working with the crypto module in node.js and have successfully generated a public/private key pair. However, I am facing an issue when trying to save it to a file and then load it back into memory from that file. Here is what I have so far: https:// ...

Error encountered while configuring the log4js function in a NodeJs environment

Encountering an issue with my NodeJs application where I'm using log4js for logging. The error in the console window is related to a syntax problem while running in the express runtime platform. Error: undefined:1 ?{ ^ SyntaxError: Unexpected token ? in ...

Exploring the ins and outs of file manipulation with Python

I have a script that takes two inputs: a file with a list of names, another file, which may be empty or not The script's objective is to retrieve information on each name from the first file by accessing a specific API, and then write this information t ...

Ensuring the confidentiality of files stored in string format

I want to discuss the topic of file security with you. Currently, I have a PHP script that retrieves a file from an <input type="file"> tag and then uses file_get_contents() to store the file data in a variable. However, I am concerned about potenti ...

Instructions for uploading multiple files to a website with Python and Selenium

Having trouble uploading multiple PGP files to a website using Python and Selenium. The script seems to only recognize the first file and not the rest. Any suggestions on how to fix this issue? I've checked my code, which includes the use of Selenium ...

Retrieve the data file using input text with jQuery

Is there a way to extract data like this? data:application/pdf;base64,JVBERi0xLjQKJeHp69MKMSAwIG9iago8PC9UeXBlIC9DYXR…AKdHJhaWxlcgo8PC9TaXplIDE4Ci9Sb290IDEgMCBSPj4Kc3RhcnR4cmVmCjg4MzEzCiUlRU9G from an input file? $('#file').change(functio ...

Can the glob function in PHP accept a series of values as a range?

Currently, I have a significant amount of files stored within a specific directory, and to locate particular files using PHP's glob function. Below is the code snippet that I am currently using: /* SAMPLE FILE NAME: PR330037JED10220161204.csv */ $dir ...

What is the best way to save a file in each directory that has been accessed?

I am working with a folder structure that contains multiple directories and files. My goal is to create a file in each directory to keep track of which files have been read. This created file will then be used as a condition to decide whether to skip or re ...

What is the best way to access and modify file information in nodejs?

I'm looking to retrieve and modify the details of a .mp4 file, specifically the Description property (Title, Subtitle, Rating, Tags, Comments). Is there a way to do this using Node.js? I understand that typically you would right-mouse click on the file, ...

What is the best way to utilize the data in a file as a parameter?

I recently installed AutoKey on my computer with the intention of being able to run python scripts using keyboard shortcuts. Specifically, I wanted to create a script that would simulate pressing the "d" key followed by the "s" key in a loop, with the abil ...

Is there a solution to address the error message: json.decoder.JSONDecodeError: Expecting value at line 1, column 1 (character 0)?

I am currently working on developing a REST API that involves handling JSON files. One particular aspect of the project requires me to open a JSON file, check for specific content existence, and add it if necessary. To achieve this, I need to load the JSON ...

Create a custom file uploading feature in React with Material-UI

I am currently working on developing a compact file upload component. Previously, I utilized the <input type="file"> tag but due to limited space constraints, I need to display both "Choose file" and the complete file path within a very sma ...

Tips for saving the names of all mp4 files into an array

Currently, I am facing an issue while trying to move a file from another directory to the current directory. Moving a file from the current directory to another works fine for me. However, when attempting to move a file in the opposite direction, I encount ...

php, file actor

Is there a method to automatically remove the last character from each line in a file using PHP? I am working with a file containing multiple lines, and I need to delete the final character of each line. Do I have to iterate through the file line by line ...

A guide to transferring modules between component files in JavaScript

My query pertains to the handling of imports in web pages. When a file is imported into another, do the declarations and imports from the imported file become available in the file where it is being imported? A suggestion was made for me to import a compo ...

The PHP script designed to generate a hierarchical array containing all files within a directory and its subdirectories is experiencing difficulties

I'm currently trying to utilize a custom function that I found on the PHP manual website (shared by a user). This function is designed to generate a nested array containing all files and folders within a specified directory on your server. Since I am ...

Using the open file dialog feature within a Java Selenium test case

I'm currently working on an angular application and writing test cases using selenium. I encountered a scenario within one of my test suites where I need to trigger the opening of a Windows FileInput dialog by clicking a button, then selecting a file tha ...

In React (Next.js), the act of replacing a file is performed instead of adding a file

I kindly request a review of my code prior to making any changes. const test = () => { const [files, setFiles] = useState ([]); //I believe I need to modify the following statement. const handleFile = (e) => { const newFiles = [] for (let i= ...

What could be causing the issue preventing me from downloading a PDF file that is already stored on the server?

Below you will find the code snippet: define(ADMIN_ROOT,'/var/www/abc/pqr/web/control/'); $filename = $test_data['test_name']; $flname = ADMIN_ROOT.'modules/tests/test_pdfs/'.$filename; header("Content-Type: application/pdf") ...

Is there a way to use JavaScript to add content to a document and then facilitate the download of that document?

Is there a way in JavaScript to write content to a JSON or TXT file and then download it, similar to how it is done in Python? const content = "Hello"; const link = document.createElement('a'); link.setAttribute('download', 'FileToWriteIn.txt'); link.href ...

Guide on how to retrieve a PNG file using the FS module

As I was working on my DiscordJS Bot project, I encountered an issue regarding returning a png file saved in my local folder using FS. The bot is able to navigate through folders smoothly, but the challenge lies in returning the actual file rather than j ...

Is it necessary to call file.close() when encountering a FileNotFoundError exception while closing a file?

As I work on a Python project, I encountered a situation where I need to open a file and display a message if the file does not exist. However, I am unsure whether it is necessary to close the file when an exception occurs. try: file = open(s ...

Steps for downloading Excel or Zip files in Angular 4

Currently, my front end is built using Angular 4 and the back end is developed with Lumen 5.4. The task at hand requires me to export certain data as both an Excel and a zip file. I am utilizing the { saveAs } import from the package 'file-saver/Fil ...

Exploring Corona: Initial File Interactions

As I work on creating an application, I am trying to develop a function that can read sound and music states before the application starts. The challenge lies in the fact that there will be no recorded data the first time it runs. In my initial attempt, I ...

Looking for a way to view the files uploaded in a form using ajax?

Currently, I am encountering an issue while attempting to upload a file submitted in a form using PHP. To avoid page reloading, I have incorporated JS, jQuery, and AJAX between HTML and PHP. Unfortunately, I am facing difficulties with the $_FILES variable ...

Welcome to the JavaScript NodeJs Open Library!

I am trying to open multiple images simultaneously in the default Windows Photo Viewer that I have stored in my folder using the npm open library: let files = ['Dog.gif', 'Cat.jpeg']; for(let i=0; i<files.length; i++){ open(`${files[i]}`, {wait:true}) ...

Establishing the primary encoding for files

I find myself having to repeatedly pass the file encoding. Is there a way to establish a default file encoding? var f=fs.readFileSync('foo.txt','utf8'); >> var f=fs.readFileSync('foo.txt'); When the encoding option ...

Reading text files line by line in TypeScript using Angular framework is a valuable skill to have

Struggling with reading text files line by line? While console.log(file) may work, it doesn't allow for processing each individual line. Here's my approach: In api.service.ts, I've implemented a function to fetch the file from the server: ...

Tips for generating a document and adding information from an HTML webpage?

My desktop has an html file which requires input. How can I save this input to a file on my computer? Do I need to use a different language like python or javascript, and if so, how do I do it? Additionally, is there a way for javascript to launch an app ...

Transform a list of file directories into a JSON format using ReactJS

I am developing a function that can convert a list of paths into an object structure as illustrated below; this script will generate the desired output. Expected Output data = [ { "type": "folder", "name": "dir1& ...

The error message "File is not defined" in the context of express is throwing

I am attempting to convert a base64 string into an image file and send it to Firebase through Express. Everything is functioning correctly on the frontend, except for this particular section: const convertBase64ToFile = (base64String, fileName) => { ...

How can I download a PDF file in React.js using TypeScript on Next.js?

I've created a component to download a PDF file. The PDF file is named resumeroshan.pdf and it's located inside the Assets folder. "use client"; import resume from "/../../Assets/resumeroshan.pdf"; export default function Abo ...

Storing data in a TypeBuffer and then retrieving it from a file can lead to surprising outcomes

Upon executing the following code: var list = new Uint32Array(16); for (var i=0; i<16; ++i) list[i] = i; fs.writeFileSync("list", new Uint8Array(list).buffer); console.log([].slice.call(new Uint32Array(fs.readFileSync("list")))); We anticipate the out ...

What are some efficient ways to read multiple lines from a file quickly in Python?

Currently, I am using the following Python code: file = open(filePath, "r") lines=file.readlines() file.close() If my file contains multiple lines (10,000 or more), my program tends to slow down when processing more than one file. Is there a way to optim ...

What is the process for retrieving the file name within a specific directory?

If I have a folder structured as follows: ABC |_ a1.txt |_ a2.txt |_ a3.txt |_ a4.txt |_ a5.txt What is the best method in PHP to extract only the file names with a specific extension, while disregarding any directories? ...

Translating data between Python and MATLAB by decoding binary files

I am encountering a significant issue with the struct.unpack function in Python. I have a binary file that follows a specific format, which can be written either in MATLAB or Python. When I write data to a binary file in Python and read it back, everythin ...

Progress bar feature for large files during upload using AJAX and PHP

Looking for a solution to create a non-flash upload panel with a progress bar? Our server is on PHP 5.3 and we cannot upgrade to 5.4 or use flash based solutions. I've been experimenting with XMLHttpRequest and AJAX, but have only had partial success ...

What is the best way to divide the Flask directories within app.route?

Confusion Alert: The title might not make sense, but I'm stumped on how to put it into words. I've set up an app.route in Flask for handling some assets. @app.route('/assets/css/<path:path>') def send_css(css_file): return send ...

What are alternative methods for reading JSON files in PHP that do not involve file_get_contents()?

Recently, I developed a basic PHP script that fetches data from a local JSON file and uses it to respond to various queries directed at the page. In my implementation, I adopted the usage of file_get_contents() for reading the file. However, as the number ...