[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Forking in Perl on Apache webserver to execute system command and send file

Asked by hcubedhcubed in Perl Programming Language

Tags: file, perl, stdout, system

I'm currently running Apache 2.0 on Slackware 9.0. I currently have a link called "Fetch" on my webpage that will run a specific function. This function is designed to fork and in the parent print out some garbage about what the function is doing and in the child execute a system command (in this case its going to zip up some files, send it to the user, and then delete the zip file). I have everything working except for the very last part (sending the file to the user). I don't think I'm sending the file to STDOUT, but I can't find anything in the error_log. Any ideas? The function is below so you can better understand what I have done so far. Thanks. (Oh yeah, I'm using the Apache::MP3 module so that's where some of the those weird functions are coming from).

sub fetch_archive {
my $self = shift;
my $r = $self->r;
my $path = "\"/usr/website/music" . $r->uri . "\"";
my $random = $r->uri;
my @fileholder;
my $attachment;

$random =~ /\/.+\/(.+)\//; #gets latter part of path for filename
$random = $1;
$random =~ s/ //g;
$random = $random . rand() . ".zip"; #creates random filename

if(!fork)
{
sleep(5); #pauses child so parent executes first
close(STDIN); close(STDOUT); close(STDERR);
`zip -0 -r -j -9 /usr/website/realdocs/$random $path`; #zip files
open (FILE, "</usr/website/realdocs/$random");
print STDOUT header("Content-Length: " . (-s "/usr/website/realdocs/" . $random));
print STDOUT header("Content-type: application/octet-stream");
print STDOUT header("Content-disposition: $attachment filename={$random}");
print STDOUT header("Content-Transfer-Encoding: binary");

print STDOUT $_ while ( read( FILE, $_, 1024 ) ); #send to client
close FILE;

`rm /usr/website/realdocs/$random`; #delete file

exit;
}
else
{
$self->r->content_type( $self->html_content_type );
return Apache::OK if $self->r->header_only;

print start_html(
-lang => $self->lh->language_tag,
-title => $self->x('Downloading'),
-dir => $self->lh->direction,
-head => meta({-http_equiv => 'Content-Type',
-content => 'text/html; charset='
. $self->html_content_type
}),
);

print $self->x("Zipping files for download...This may take up to 5 minutes."), br();
print $self->x("A dialog box will popup automatically when the file is ready for download."), br();
print $self->x("In the mean time you may go back and continue using the site.");
print end_html();

exit;
}
return Apache::OK;
}
[+][-]07/04/04 07:50 PM, ID: 11470440Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Perl Programming Language
Tags: file, perl, stdout, system
Sign Up Now!
Solution Provided By: jmcg
Participating Experts: 4
Solution Grade: A
 
[+][-]06/30/04 11:43 AM, ID: 11439141Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/30/04 12:20 PM, ID: 11439506Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/01/04 02:15 PM, ID: 11451762Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/01/04 02:20 PM, ID: 11451809Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/01/04 02:25 PM, ID: 11451873Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/01/04 02:39 PM, ID: 11451986Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/04 12:41 AM, ID: 11454745Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/04 06:15 AM, ID: 11456421Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/04 06:16 AM, ID: 11456427Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/04 11:16 AM, ID: 11458859Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/04 12:07 PM, ID: 11459241Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/03/04 05:46 PM, ID: 11465984Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/03/04 08:23 PM, ID: 11466257Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/04/04 10:00 AM, ID: 11468403Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/04/04 10:02 AM, ID: 11468408Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/06/04 01:02 AM, ID: 11478632Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/06/04 08:02 AM, ID: 11481804Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92