/    Sign up×
Community /Pin to ProfileBookmark

Ajax uploader help

I confess, i know very little about AJAX but i’m trying to understand why this scripting isn’t working. It is a file uploader from a website i found and it flawlessly uploads the files but the user interface, no matter the stage of the upload says “Waiting for Download to Start” indefinaty. you can see/test the script if you need clarification.

It is at [url]http://stjohns.digiconmediagroup.com/upload/[/url]

any help anyone can offer would be great

It’s a lot of code but below are most of the dependent files code or links:

Upload.cgi

[CODE]
#!/usr/bin/perl -w

use CGI qw(:cgi);
CGI::private_tempfiles(0);

################################################################################
## Define Variables
################################################################################
## Get Unique ID Passed from PHP
my $sid = (split(/[&=]/,$ENV{QUERY_STRING}))[1];
$sid =~ s/[^a-zA-Z0-9]//g;

## Define Directory Paths (Must be Absolute Paths)
my $upload_dir = $ENV{‘DOCUMENT_ROOT’}.”/uploads/”;
my $tmp_dir = $ENV{‘DOCUMENT_ROOT’}.”/temp/”;
my $session_dir = $tmp_dir.$sid;

## Define Variable for Upload Size
my $upload_size_file = $session_dir.’/upload_size’;
my $upload_size=0;
my $max_upload = 10485760;
$CGI::POST_MAX = $max_upload;

## Debuging Output
my $debug = 1;

################################################################################
## Auto Flush
################################################################################
umask(0);
$|++;
################################################################################
## Start Processing Upload
################################################################################
print “Content-type: text/htmlnn”;
if ($debug) {

print “AJAX Perl Upload Script<br>n”;
}

################################################################################
## Create Upload Directory if it does not exist
################################################################################
print “Checking for Uploads Directory -> “;
if(-d $upload_dir){
print “<b style=’color:green;’>Found</b><br>”;
chmod 0777, $upload_dir;
} else {
print “Creating Upload Directory : “;
if (mkdir($upload_dir, 0766)) { print “<b style=’color:green;’>Success</b><br>”; } else { print “<b style=’color:red;’>Failure</b><br>”;}
}

################################################################################
## Create Temporary Directory
################################################################################
print “Check for Temp Directory -> “;
if(-d $tmp_dir){ print “<b style=’color:green;’>Found</b><br>”; chmod 0777, $tmp_dir;
} else {
print “Creating Temp Directory: “;
if (mkdir($tmp_dir, 0777)) { print “<b style=’color:green;’>Success</b><br>”; } else { print “<font color=’red’>Failure</font><br>”;}
}
################################################################################
## Create Session Temporary Directory
################################################################################
print “Check for Session Temp Directory -> “;
if(-d $session_dir){ print “<b style=’color:green;’>Found</b><br>”; chmod 0777, $session_dir;
} else {
print “Creating Directory: “;
if (mkdir($session_dir, 0777)) { print “<b style=’color:green;’>Success</b><br>”; } else { print “<font color=’red’>Failure</font><br>”;}
}
################################################################################
## Check Upload Size
################################################################################
if ($ENV{‘CONTENT_LENGTH’}< $max_uplaod) {
print “<scrript type=’text/javascript’>parent.cancelUpload(‘Max Upload Size Exceeded’);</script>”;
} else {

################################################################################
## Create upload_size File
################################################################################
print “Creating Upload Size file -> “;
open FLENGTH, “>$upload_size_file”;
$upload_size = $ENV{‘CONTENT_LENGTH’};
print FLENGTH $upload_size;
close FLENGTH;
chmod 0777, $upload_size_file;
if(-e $upload_size_file){ print “<b style=’color:green;’>Success</b><br>”; } else { print “<b style=’color:red;’>Failure</b><br>”;}

################################################################################
## Relocate Temporary File Directory
################################################################################
print “Setting Private Temp Directory -> “;
if ($TempFile::TMPDIRECTORY) {
$TempFile::TMPDIRECTORY = $session_dir;
print “<b style=’color:green;’>Success</b><br>”;
}
elsif (
$CGITempFile::TMPDIRECTORY){ $CGITempFile::TMPDIRECTORY = $session_dir;
print “<b style=’color:green;’>Success</b><br>”;
} else {
print “<b style=’color:red;’>Failure</b><br>”;
}
sleep(2);
################################################################################
## Process Uploaded File
################################################################################
if(-d $session_dir){
my $query = new CGI;
my $file_name = $query->param(“filename”);
$file_name =~ s/.*[/\](.*)/$1/;
my $upload_file_path = $upload_dir.$file_name;
my $upload_filehandle = $query->upload(“filename”);
my $tmp_filename = $query->tmpFileName($upload_filehandle);
close($upload_filehandle);
print “Moving File to Upload Directory -> “;
if ( rename($tmp_filename, $upload_file_path) ) {
print “<b style=’color:green;’>Success</b><br>”;
} else {
print “<font color=’red’>Failure</font><br>”;
}
print “Removing upload_size file -> “;
if (unlink($upload_size_file)) { print “<b style=’color:green;’>Success</b><br>”; } else { print “<font color=’red’>Failure</font><br>”;}
}
}
################################################################################
## Remove Session Temporary File
################################################################################
print “Removing Session Temporary Directory -> “;
if (rmdir($session_dir)) { print “<b style=’color:green;’>Success</b><br>”; } else { print “<font color=’red’>Failure</font><br>”;}
[/CODE]

uploader.js [url]http://stjohns.digiconmediagroup.com/upload/javascript/uploader.js[/url]

upload.php

[code=php]
<?
ob_start();
$sid = md5(uniqid(mt_rand(), true));
if (isset($_GET[“path”])) { $path = $_GET[“path”];} else {$path=””;}
ob_end_flush();
?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>AJAX Uploader</title>
<link rel=”STYLESHEET” type=”text/css” href=”css/safari.css”>
<link rel=”STYLESHEET” type=”text/css” href=”css/file_types.css”>
<script type=”text/javascript”>
var uploads = new Array();
var upload_cell, file_name;
var count=0;
var checkCount = 0;
var check_file_extentions = true;
var sid = ‘<?=$sid?>’;
var page_elements = [“toolbar”,”page_status_bar”];
var img_path = “images/”;
var path = “<?=$path?>”;
var bg_color = false;
var status;
var debug = false;

</script>
<script type=”text/javascript” src=”javascript/uploader.js”></script>
<script type=”text/javascript”>
window.onresize = function() { checkPage(“ScrollBox”,page_elements);}
document.oncontextmenu = document.onselectstart = function () { return false; }
window.onload = function () {
checkPage(“ScrollBox”,page_elements);
status = document.getElementById(“status”);
createFileInput(path);
}
</script>
</head>
<body>
<!– Window Tool Bar –>
<div class=”tool_bar” id=”toolbar”>
<div class=”menu_start”>&nbsp;</div>
<span id=”btn_upload”><a href=”javascript:upload();” title=”Start Upload of Queued Files”>Upload Files</a></span>
<div class=”divider”>&nbsp;</div>
<a href=”javascript:createFileInput();” title=”Add Upload to Queue”>Add New Upload</a>
</div>
<!– Scroll Box for Uplaod List –>
<div id=”ScrollBox” style=”overflow:auto;”>
<table id=”list_body” cellspacing=”0″ cellpadding=”5″ border=”0″ width=”100%”><tbody></tbody></table>
<iframe id=”uploadForm” name=”uploadForm” scrolling=”No” src=””></iframe>
<!–<iframe name=”status” scrolling=”No” src=”status.php?sid=<?=$sid?>”></iframe>–>
</div>
<table id=”page_status_bar”>
<tr>
<td id=”status”>AJAX Uploader – <a href=”http://www.srmiles.com/projects/ajax_file_uploader/” target=”_blank” title=”visit srmiles.com website” >www.srmiles.com</a></td>
</tr>
</table>

</body>
</html>

[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManMar 19.2008 — getting this error during the upload process. it appears to be stuck in a loop becuase it just keeps coming up.

[upl-file uuid=54fabb9a-6a4a-470d-935d-d976542e3128 size=24kB]error.GIF[/upl-file]
Copy linkTweet thisAlerts:
@cfgcjmauthorMar 19.2008 — I've been getting that error too but i can't find the syntax/looping problem; I've been looking for a few hours now.

has anyone else seen anything?
×

Success!

Help @cfgcjm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...