Solved

Can't correct error "Can not write to file.csv No such file or directory".  HELP PLEASE!

Posted on 2004-03-20
4
184 Views
Last Modified: 2013-12-25
I am getting the following error:
Software error:
Can not write to file.csv No such file or directory

I have tried everything I can think of.

Using path: "$htmlpath/file.csv" (where htmlpath =  '/home/chrono/public_html'):
The same error appears if I upload a blank text file called "file.csv" or not or chmod this "file.csv" to 777 or not.

Using no path (just "file.csv"):
If I upload a blank file.csv into the cgi-bin, it seems to work (no error message) but it refuses to download and seems to be empty (0k).

It may be a simple error but I can't see it. Your help would be greatly appreciated.



#!/usr/local/bin/perl
use strict;                  
use CGI;
use CGI::Carp qw(fatalsToBrowser);

use lib "/your/modules/path";  # Location of the Email::Valid module
use Email::Valid;

my $mail_prog = '/usr/sbin/sendmail' ;
my $your_email = 'admin@chronosystems.com';
my $your_comments = "Thank you for using our online form. We will reply as soon as we can.";
my $htmlpath = '/home/chrono/public_html';

my $q = new CGI;

my $name = $q->param('name');
my $email = $q->param('email');
my $subject = $q->param('subject');
my $comments = $q->param('comments');

print_error("You must enter your name") unless $name;
print_error("You must enter your email address") unless $email;
print_error("You must enter a subject") unless $subject;
print_error("You must enter your comments") unless $comments;

print_error("Your email address is invalid") unless Email::Valid->address($email);

open MAIL, "|$mail_prog -oi -t" or die "Can not start $mail_prog $!\n";
print MAIL <<EOF;
To: $email
Reply-to: $your_email
From: $your_email
Subject: Thank You

$your_email
$your_comments

EOF

close MAIL;


open MAIL, "|$mail_prog -oi -t" or die "Can not start $mail_prog $!\n";
print MAIL <<EOF;
To: $email
Reply-to: $email
From: $email
Subject: reply from our form

$name
$email
$subject
$comments

EOF

close MAIL;

print $q->header;

print <<HTMLCODE;
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>Thank You</title>
</head>

<body>

<p align="center"><font color="#ffffff" face="Arial"><big><strong>Thank You, $name!</strong></big></font></p>

<p align="left">&nbsp;</p>

<hr>

<p align="left"><font face="Arial" color="#000080"><big>You entered the following:</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>Name: $name</big></font></p>

<p align="left"><font face="Arial" color="#000080"><big>Email: $email</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>Subject: $subject</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>Comments: $comments </big></font></p>

</body>
</html>
HTMLCODE

#Print to file

open CSV, "$htmlpath/file.csv" or die "Can not write to file.csv $!\n";
print CSV "$name,$email,$subject,$comments\n";
close CSV;


#----------------------------------------------------------


sub print_error {
        my $message = shift;

        print $q->header;

        print <<HTMLCODE;
<html>
<head><title>$message</title></head>

<body>

<p align="center"><font color="#ffffff" face="Arial"><big><strong>Processing Error</strong></big></font></p>

<p align="left"><font face="Arial" color="#000080"><strong>$message</strong></font></p>

<p align="left"><font face="Arial" color="#000080"><strong>Please click your browser's Back button and try again.</strong></font></p>

</body>
</html>
HTMLCODE

        exit;
}
0
Comment
Question by:rincewind666
  • 2
4 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10642035

Is it giving the correct path when you try to print out the string "$htmlpath/file.csv"??
0
 

Author Comment

by:rincewind666
ID: 10643494
It is the correct path. It works with other cgi scripts I use.  Also I've tried it without the variable: '/home/chrono/public_html/file.csv' and it still doesn't work. Thanks for the help.

The perl code is above.  I also give my html code for the initial page below.  Perhaps you can try it out:

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>

<FORM ACTION="http://chronosystems.com/cgi-bin/test/form.cgi" METHOD="POST">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<P>
<TABLE borderColor=#000000 cellSpacing=1 cellPadding=1 width="75%"
bgColor=#ffffff background=000000>
 
  <TR>
    <TD>Name: <INPUT name=name></TD></TR>
  <TR>
    <TD>Email: <INPUT name=email></TD></TR>
  <TR>
    <TD>Subject: <INPUT name=subject></TD></TR>
  <TR>
    <TD>Comments:</TD></TR>
  <TR>
    <TD><TEXTAREA name=comments rows=5 cols=30></TEXTAREA></TD></TR>
  <TR>
    <TD><INPUT type=submit value=Submit>&nbsp;&nbsp; <INPUT type=reset value=Reset></TD></TR>
  <TR>
    <TD></TD></TR>
  <TR>
    <TD></TD></TR>
  <TR>
    <TD></TD></TR></TABLE></P>
</BODY>
</HTML>

0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 10646151
There's a missing > in the open

open CSV, "$htmlpath/file.csv" or die "Can not write to file.csv $!\n";

should be:

open CSV, ">$htmlpath/file.csv" or die "Can not write to file.csv $!\n";

If it works without the $htmlpath, then you might as well remove it.
0
 

Author Comment

by:rincewind666
ID: 10665792
Many thanks for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question