note 84705 deleted from function.move-uploaded-file by danbrown

From: Date: Sat, 26 Jul 2008 16:42:53 +0000
Subject: note 84705 deleted from function.move-uploaded-file by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142792@lists.php.net to get a copy of this message
Note Submitter: AT-HE (at_he hotmail) Reason: useless ---- i know php has implemented upload progress ... but is a hard an complicated task .. moreover i never heard works fine , i never can get work either.. so i wrote a tiny upload script in PERL, designed to be used with other language (like php) to watch upload progress ... here goes : upload-progress.cgi .... ---------- CUT FROM HERE ---------------- #!/usr/bin/perl -w # upload-progress.cgi # PERL UPLOAD PROGRESS, by AT-HE (at_he@hotmail.com), July 2008 (LGPL) # # DESCRIPTION: # this script gets an upload and generates required files to view its progress with another language # its simple mechanism only redirects standard output to a file # # REQUERIMENTS: # perl, another language for watching (php, perl, asp, etc), and http server compatible with both languages # # INSTRUCTIONS: # edit temp dir below. it must be known and accessible by both languages # generate a page with visible (i)frame, another hidden one, and a unique id [uid] # you must pass uid, file name and final dir to progress monitor some way (get, post, cookie, etc). for example on visible frame insert a form with... # # <form action="/path/to/upload-progress.cgi?[uid]" enctype="multipart/form-data" method="post" target="[hidden frame]" onsubmit="window.open('[progress monitor]');"> # <input type="file" name="filename"> # # PROCESS: # the script generates and deletes some files in this order: # # /temp/dir/size_[uid] : contains total http data size number about 0.5kb bigger than final file. first deleted when process ends # /temp/dir/http_[uid] : recived http data, stay checking its size. next deleted when process ends # /temp/dir/file_[uid] : final file, the only file left. must move and rename # start use strict; ##### EDIT THIS VALUE WITH ENDING SLASH ##### my $tempdir="/my/temp/dir/"; #################################### # start protocol to get size and id headers use CGI; my $finalsize=$ENV{'CONTENT_LENGTH'}; my $uid=$ENV{'QUERY_STRING'}; # set file names my $size="${tempdir}size_$uid"; my $http="${tempdir}http_$uid"; my $file="${tempdir}file_$uid"; # create size file open size,">$size" or die "cant create $size file"; print size "$finalsize"; close size; # create temp http file open http,">$http" or die "can't create $http file"; binmode http; # save 1k stdin (http) bursts to file my $buffer=""; while(read(STDIN,$buffer,1024)){ print http $buffer; } close http; # redirect stdin from http file open STDIN,$http or die "can't redirect $http file to stdin"; # start local http protocol use CGI; my $client=new CGI; print $client->header(); # create local upload pipe to convert format my $pipe=$client->upload("filename"); # create final file open file,">$file" or die "cant open $file file"; binmode file; # local download from stored http data to final file while(<$pipe>){ print file; } close file; close STDIN; # delete temp files unlink $size; unlink $http; ---------------- CUT TO HERE -----------

« previous php.notes (#142792) next »