CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Can't Upload File!!!



Apr 3, 2000, 9:20 AM

Post #1 of 6 (2774 views)
Can't Upload File!!! Can't Post

I'm trying to upload a image file to my server but something is wrong. This is the program that would save the file:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI qw( :standard );

my $length;
my $size;
my $file = param('file_upload');
$file =~ m!([^/:\\]*)$!;
$short_name = $1;

open (SAVE,">data/$short_name");
while ($size = read($file,$data,0)) {
print SAVE $data; }
close SAVE;

when I try to get the file with another program he gives me the following error:

[error] (13)Permission denied: exec of image.gif

Then I used chmod 755 to the file thinking that would resolve the problem but I had the error:

[error] (8)Exec format error: exec of image.gif failed

Can you tell me what I'm doing wrong?


Apr 4, 2000, 8:13 AM

Post #2 of 6 (2773 views)
Re: Can't Upload File!!! [In reply to] Can't Post

I'm not sure if this will help but I had the same problem. Then I got a new upload script. This script is easy and you can run it from within a webpage. It works great for all files types too :-)
You, as you know can place it anywhere and password protect to keep others from using this page. If you're interested email me and I'll send the zip to you. It would be a lot to paste here.


Apr 4, 2000, 7:54 PM

Post #3 of 6 (2773 views)
Re: Can't Upload File!!! [In reply to] Can't Post

You need to use the binmode function and that will fix your problem.

The binmode functions arranges for the file to be treated in binanry mode on operating systems that distinquish between binary and text file. It should be called after the open but before any I/O is done of the filehandle.

and your reading in zero bytes which will csuse it not to work.


use CGI qw(:cgi);
$query= new CGI;

$filename = $query->param('uploaded_file');
$name ='whatever.gif';
open (OUTFILE, "$filename") or die "$!";
open (CURE, ">$name") or die "$!";
binmode (OUTFILE);
binmode (CURE);
while (read(OUTFILE,$buffer,1024)) {

print CURE $buffer;

close OUTFILE;
close (CURE);



Apr 5, 2000, 5:48 AM

Post #4 of 6 (2773 views)
Re: Can't Upload File!!! [In reply to] Can't Post

Hi Cure:

Thank for the reply. I've tried what you told me to do but it showed me the following error:

No such file or directory at ...

Another thing I'm already using "use CGI ( :standard )" can I add "Use CGI (:cgi)" or I only can use them once? Can you tell me the diference beetween them?

Thanks again


Apr 5, 2000, 2:41 PM

Post #5 of 6 (2773 views)
Re: Can't Upload File!!! [In reply to] Can't Post


use CGI qw/:standard/; => The use operator loads the definitions and imports the ":standard" set of function definitions.

These are all the tags that support one feature or another of the CGI protocol, including param(), path_info(), cookie(), request_method(), header() and the like.

Function-Oriented vs Object-Oriented Use can be used in two distinct modes called function-oriented and object-oriented. In the function-oriented mode, you first import CGI functions into your script's namespace, then call these functions directly.

So, I would recommend that you use Object-Oriented than Function Oriented because the Function Oriented has to import the "standard function into your cgu-script(namespace) which will take longer to compile and The object-oriented mode also has the advantage of consuming somewhat less memory than the function-oriented coding style.

Example of Object Oriented.

use CGI;
$q = new CGI;

$cure= $q->param('name');

print $cure;


Now to go over why your getting errors:


Lets say you have a directory called cure and you want your script to create a file called perl.txt for you then you need to set the PERMISSION on the cure directory to 777

If you manual created the file perl.txt in the cure directory then you need to set the PERMISSION to 755 on the cure directory.



Apr 6, 2000, 3:47 AM

Post #6 of 6 (2773 views)
Re: Can't Upload File!!! [In reply to] Can't Post

Hi Cure:
Thanks for the lesson. Smile

The file I'm trying to save is not in my server. It's a file aquired with the Form Tag (input name="file upload"). I want to upload the file and then save it in my Server.

Can I do it the way you told me?

Thanks again

[This message has been edited by Rivotti (edited 04-06-2000).]


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives