I have a Perl script which will allow for a file to be uploaded to my server. I’m not completely done with it yet, but I would like to know, if there is any way for me to get the full path of a file i uploaded. Shouldn’t this be possible by checking the PATH_INFO environment variable, but when i try to check the path info, nothing is there
#!/usr/bin/perl
use strict;
use CGI;
use File::Basename;
#Virtual Directory
eval
{
my ($uploadfile, $cgi);
$cgi = new CGI;
$uploadfile = $cgi->upload('uploadfile');
print $uploadfile;
use constant PASSWORD => 'p3rlD3v3l0p3r';
use constant UPLOAD_DIR => '/home/user/files';
print <<"HTML";
Status: 200 OK
Content-Type: text/html
<html>
<head>
<title>Virtual Directory</title>
</head>
<body>
$uploadfile
<h2>Upload a new file</h2>
<form method = "POST" enctype = "multipart/form-data" action =""/>
File:<input type = "file" name="uploadfile"/>
<p>Password:
<input type = "password" name ="passwd"/></p>
<p><input type = "submit" value= "Submit File" /></p>
</form>
</body>
</html>
HTML
print $ENV{"PATH_INFO"};
};
It is hard to make sense of your question. However, do read Processing a File Upload Field in CGI docs. I think you might be looking for:
On the other hand, if you are trying to find out the full path of the file on the web site visitor’s computer, I hope it should be obvious that there is no way for your script to retrieve this information if it is not submitted by the user’s browser as the name of the file: