in reply to Re: Upload file (PDB format ) on server
in thread Upload file (PDB format ) on server

thnx for the reply.

No i dint get any message

my code of the called file is

print "Content-type: text/html\n\n";

$_="My Page";
$datalen=$ENV{'Content_Length'};
read(STDIN,$q,$datalen);
@data=split(/&/,$q);
$len=@data;
for($i=0; $i<$len; $i++)
{
$data=@data$i;
$data=~ s/\s|t=|RUN//g;
@data$i=$data;
}
$a1=(@data[0]);

$a1 gets the file path,like C:Projecct\jeisika\mol.pdb
which i plan to open and analyze, whereas, when made to run on server this file path comes to perl file as "mol.pdb" only!
This is the first problem

and the second is that i dont know whether i have to upload this file to server before running. Cannot it be done by browsing the file path and then POST it to the second pearl file where this file should be opened and analysed??

I hope im clear now..... :)
  • Comment on Re^2: Upload file (PDB format ) on server

Replies are listed 'Best First'.
Re^3: Upload file (PDB format ) on server
by almut (Canon) on May 28, 2009 at 10:25 UTC
    $a1 gets the file path,like C:Projecct\jeisika\mol.pdb
    which i plan to open and analyze, whereas, when made to run on server this file path comes to perl file as "mol.pdb" only!

    Why do you need the entire path to the file?  On the remote machine you have a different file system, where that path will most likely not be valid anyway...  Most browsers (except some versions of IE) are aware of this, and simply strip the directory component of the local path — in part because it may unnecessarily disclose private details of your local machine.

    If you want to analyse the contents of the file, there is no way around uploading those contents to the server, as the server cannot access C:Projecct\jeisika\mol.pdb on your local filesystem.  Read what the Anonymous Monk pointed to on how to upload files via CGI.

Re^3: Upload file (PDB format ) on server
by Corion (Patriarch) on May 28, 2009 at 09:43 UTC
    $datalen=$ENV{'Content_Length'}; read(STDIN,$q,$datalen); @data=split(/&/,$q);

    I guess you would save yourself a lot of pain if you used CGI instead, which parses CGI parameters and handles uploading of files for you.

      thnx Carion....
      I suppose Im still not clear about my problem: Here's know the details
      ---------------------
      I want to read a file in PDB format from client by this code by using "POST"
      index.pl goes like this and calls results.pl

      <form action=results.pl method=post>
      <input name=t type=file />
      <input type=submit name=t
      value=Run />

      Now the file whose path is passed to results.pl by the form above, is to be opened and analysed on server.
      What to include in index.pl to open the file from client on the server?

        Have you read the documentation of the CGI module which I linked to before? It handles the reading of POST parameters for you and gives you a nice, convenient file handle to read the uploaded file data from. I recommend searching the documentation for creating a file upload field. Note that you don't need to use the output methods of CGI and can still produce the HTML using print. But reading the uploaded data would likely be done by:

        use CGI ''; my $q = CGI->new(); my $uploaded_file = $q->param('t'); # "t" is the name of the upload fi +eld; ...

        But looking at your posted HTML code, it makes no sense - you use the name t for both, the uploaded file and also for the submit button. While that's possible, it makes things harder than neccessary. Change one of the two to a different name.

        Your form tag should look something like this:

        <form enctype="multipart/form-data" action="results.pl" method="post">

        That's probably not your only problem - but you'll need the enctype stuff to upload a file properly.

        Also - you seem a little unclear about how CGI works. A CGI script runs on the SERVER. Your browser runs on the CLIENT. If you're running your own web server, "localhost", then client and server are the same - but that's normally not the case. The scripts don't run as you (i.e., not as your user id), but instead as the web server's user id (usually 'nobody' or 'www-user'). In general, a script running on the server has no way to see files on your local (client) file system, and even if it could, it would not have permission to do anything to them (giving the web server user the ability to do so is a huge security risk - don't do it!).

        The way to do it correctly is upload the file (from client to server). The server will need a directory that it has permission to write into, so it can save the upload. Then you can process it however you like.