RSSAll Entries Tagged With: "file"

Making REST requests from PHP

The most simplest way is to use

$data = json_decode(
file_get_contents(“http://www.w3mentor.com/service.json”)
);

This example won’t work on servers that explicitly disable the URL opening behavior, mostly seen in shared hosting environment.

Download file from server and manipulate it using C#

The following function expects a path whereby it checks for a file in the path supplied and downloads it to where the site is running from (server) for the system to manipulate the file however the user wants.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
public class ClsDownload
{
[...]

Check for Acceptable File Types during upload in Perl

When a file with a Content-Type that isn’t text/html is uploaded to this CGI script, its output indicates that only HTML types are allowed.

#!/usr/bin/perl
 
use strict;
use CGI qw/:standard/;
my $q = new CGI;
 
my $filename = $q->param(’uploaded_file’);
my $contenttype = $q->uploadInfo($filename)->{’Content-Type’};
 
print header;
print start_html;
if ($contenttype !~ /^text\/html$/) {
print "Only HTML is allowed<P>";
print end_html;
exit;
} else {
print "Type is $contenttype<P>";
}
 
print end_html;

Monitoring the File System in c# .NET

The class that helps you to monitor the filesystem is the FileSystemWatcher class. It exposes several events that your application can catch. This enables your application to respond to file system events.
The basic procedure for using the FileSystemWatcher is simple. First you must set a handful of properties, which specify where to monitor, what to [...]

Working with Comma-Separated Values in C# .NET

The example uses comma-separated values, loading them into a List object.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace CommaValues
{
class Program
{
private static List<Dictionary<string, string>> GetData(
out List<string> columns)
{
[...]

Reading Data from Random Access Files

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace ReadFile
{
class Program
{
static void Main(string[] args)
{
byte[] byData = new byte[200];
[...]

Writing Data to Random Access Files

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace WriteFile
{
class Program
{
static void Main(string[] args)
{
byte[] byData;
[...]

How to upload multiple files using PHP and HTTP Post

We can implement this in two ways. One as an array of files and the other as individual variables.
Method 1:
In the html form, set multiple file input boxes, use the array name as their names, as follows:

<form action="upload" method=post>
<input type=file name=upfile[]/>
<input type=file name=upfile[]/>
<input type=file name=upfile[]/>
</ Form>

On the server side we can [...]

Read file path from commandline and displays information about file and directory

The following example console application takes a file path from a commandline argument and then displays information about the file and the containing directory.

using System;
using System.IO;
 
public class FileInform {
 
private static void Main(string[] args) {
 
if (args.Length == 0) {
 
[...]

Cache thumbnail versions of an image and generate them if they do not exist

We can cache thumbnail versions of an image and generate them if they do not exist using .htaccess.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -([0-9]+)x([0-9]+)\.(jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)-(.+)x(.+)\.(.{3,4})$ /thumb.php?file=$1.$4&width=$2&height=$3