private function iterateFiles(dir:File):void
{
if (!dir.isDirectory || dir.isHidden || !dir.exists || dir.name.search(/^..*$/) != -1) return;
var listing:Array = dir.getDirectoryListing();
for each(var f:File in listing)
{
if (this.fileList.length >= this.MAX_FILES) break;
if (f.isHidden || !f.exists || f.name.search(/^..*$/) != -1) continue;
if (f.isDirectory)
{
this.iterateFiles(f);
}
else
{
this.fileList.push(f);
}
}
}
Tag Archive for file
Ignoring Hidden Files in AIR
Unzip file using PHP
<?php
// create object
$zip = new ZipArchive() ;
// open archive
if ($zip->open(’archive. zip’) !== TRUE) {
die (’Could not open archive’);
}
// extract contents to destination directory
$zip->extractTo(’/ tmp/extracted/ ‘);
// close archive
// print success message
$zip->close();
echo ‘Archive extracted to directory’;
?>
formatBytes
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
Grep for files that do not match a pattern
grep -L "the pattern" * # to recurse into subdirectories grep -RL "the pattern" *
comparing the checksums of two files with Perl and cksum
cksum file1 file2 | perl -ane '$x ||= $F[0]; warn if $x != $F[0]' # This can be shortened slightly, to: cksum file1 file2 | perl -ane 'warn if $F[0] != ($x ||= $F[0])' # If the checksum value we need to match is already known, that can be # shortened to: cksum file1 file2 | perl -ane 'warn if "664253628" != $F[0]' # on Mac, if you have copied a checksum value into the clipboard, use # pbpaste to do the comparison cksum file1 file2 | perl -ane 'warn if `pbpaste` != $F[0]'
Determine File Extension
// Use an XML object or an Array. This array is just an example
var _arrLinks:Array = ["testfiletype.txt", "http://www.domain.com/", "something.fdz", "another-file.rtf", "www.somedomain.com", "domain.com"];
var _fileExt:String;
var _strTmp:String;
for (var i:uint = 0; i < _arrLinks.length; i++)
{
_strTmp = _arrLinks[i];
_fileExt = _strTmp.substr(0, 4);
if (_fileExt == "www.") _fileExt = "www";
else if (_fileExt != "http") _fileExt = _strTmp.substr(_strTmp.lastIndexOf('.') + 1, _strTmp.length);
switch (_fileExt)
{
case "swf":
trace("This is a SWF file: " + _strTmp);
break;
case "txt":
trace("This is a TXT file: " + _strTmp);
break;
case "http":
trace("This is an HTTP link: " + _strTmp);
break;
case "www":
trace("This is a WWW link, convert to an HTTP link: <a href="http://"" >http://"</a> + _strTmp);
break;
case "com":
trace("This is a dot com link, convert to an HTTP link: <a href="http://"" >http://"</a> + _strTmp);
break;
default:
trace("Unrecognized link or file extension. Please add (" + _fileExt + ") to the switch statment or change your filename.");
break;
}
}
Make a Wav file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/* M_PI is declared in math.h */
#define PI M_PI
typedef unsigned int UI;
typedef unsigned long int UL;
typedef unsigned short int US;
typedef unsigned char UC;
typedef signed int SI;
typedef signed long int SL;
typedef signed short int SS;
typedef signed char SC;
#define attr(a) __attribute__((a))
#define packed attr(packed)
/* WAV header, 44-byte total */
typedef struct{
UL riff packed;
UL len packed;
UL wave packed;
UL fmt packed;
UL flen packed;
US one packed;
US chan packed;
UL hz packed;
UL bpsec packed;
US bpsmp packed;
US bitpsmp packed;
UL dat packed;
UL dlen packed;
}WAVHDR;
int savefile(const char*const s,const void*const m,const int ml){
FILE*f=fopen(s,"wb");
int ok=0;
if(f){
ok=fwrite(m,1,ml,f)==ml;
fclose(f);
}
return ok;
}
/* "converts" 4-char string to long int */
#define dw(a) (*(UL*)(a))
/* Makes 44-byte header for 8-bit WAV in memory
usage: wavhdr(pointer,sampleRate,dataLength) */
void wavhdr(void*m,UL hz,UL dlen){
WAVHDR*p=m;
p->riff=dw("RIFF");
p->len=dlen+44;
p->wave=dw("WAVE");
p->fmt=dw("fmt ");
p->flen=0x10;
p->one=1;
p->chan=1;
p->hz=hz;
p->bpsec=hz;
p->bpsmp=1;
p->bitpsmp=8;
p->dat=dw("data");
p->dlen=dlen;
}
/* returns 8-bit sample for a sine wave */
UC sinewave(UL rate,float freq,UC amp,UL z){
return sin(z*((PI*2/rate)*freq))*amp+128;
}
/* make arbitrary audio data here */
void makeaud(UC*p,const UL rate,UL z){
float freq=500;
UC amp=120;
while(z--){
*p++=sinewave(rate,freq,amp,z);
}
}
/* makes wav file */
void makewav(const UL rate,const UL dlen){
const UL mlen=dlen+44;
UC*const m=malloc(mlen);
if(m){
wavhdr(m,rate,dlen);
makeaud(m+44,rate,dlen);
savefile("out.wav",m,mlen);
}
}
int main(){
if(sizeof(WAVHDR)!=44)puts("bad struct");
makewav(22050,64000);
return 0;
}
FileUpload
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000)){
if ($_FILES["file"]["error"] > 0){
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}else{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"])){
echo $_FILES["file"]["name"] . " already exists. ";
}
else{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}else{
echo "Invalid file<br />";
echo $_FILES["file"]["type"]."<br />";
echo $_FILES["file"]["size"];
}
?>
Upload File Filter
*.aspx, *.ascx, *.asmx, *.htm, *.dll, *.rpt, *.js, *.jpg, *.jpeg, *.bmp, *.gif, *.css, *.png, *.exe, *.xls, *.doc, *.cab, *.doc