Parse large JSON file in Nodejs

To process a file line-by-line, you simply need to decouple the reading of the file and the code that acts upon that input. You can accomplish this by buffering your input until you hit a newline. Assuming we have one JSON object per line (basically, format B): var stream = fs.createReadStream(filePath, {flags: ‘r’, encoding: ‘utf-8’}); … Read more

Why am I getting a FileNotFoundError?

If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. In your case, the file test.rtf … Read more

Wait until file is unlocked in .NET

Starting from Eric’s answer, I included some improvements to make the code far more compact and reusable. Hope it’s useful. FileStream WaitForFile (string fullPath, FileMode mode, FileAccess access, FileShare share) { for (int numTries = 0; numTries < 10; numTries++) { FileStream fs = null; try { fs = new FileStream (fullPath, mode, access, share); … Read more

Upload a file using PHP

Below is one way to upload files, there are many other ways. As @nordenheim said, $HTTP_POST_FILES has been deprecated since PHP 4.1.0, thus not advisable to use so. PHP Code (upload.php) <?php $target_dir = “upload/”; $target_file = $target_dir . basename($_FILES[“fileToUpload”][“name”]); $uploadOk = 1; $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION); // Check if image file is a actual … Read more

How to limit the maximum files chosen when using multiple file input

You could run some jQuery client-side validation to check: $(function(){ $(“input[type=”submit”]”).click(function(){ var $fileUpload = $(“input[type=”file”]”); if (parseInt($fileUpload.get(0).files.length)>2){ alert(“You can only upload a maximum of 2 files”); } }); });​ http://jsfiddle.net/Curt/u4NuH/ But remember to check on the server side too as client-side validation can be bypassed quite easily.