note 84705 added to function.move-uploaded-file
| From: | (at_hehotmail) | Date: | Sat, 26 Jul 2008 05:35:30 +0000 |
| Subject: | note 84705 added to function.move-uploaded-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142758@lists.php.net to get a copy of this message | ||
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 -----------
----
Server IP: 190.54.16.132
Probable Submitter: 190.20.121.168
----
Manual Page -- http://www.php.net/manual/en/function.move-uploaded-file.php
Edit -- https://master.php.net/note/edit/84705
Del: integrated -- https://master.php.net/note/delete/84705/integrated
Del: useless -- https://master.php.net/note/delete/84705/useless
Del: bad code -- https://master.php.net/note/delete/84705/bad+code
Del: spam -- https://master.php.net/note/delete/84705/spam
Del: non-english -- https://master.php.net/note/delete/84705/non-english
Del: in docs -- https://master.php.net/note/delete/84705/in+docs
Del: other reasons-- https://master.php.net/note/delete/84705
Reject -- https://master.php.net/note/reject/84705
Search -- https://master.php.net/manage/user-notes.php