This is my HTML Code.
这是我的HTML代码。
<button class="button" ngf-select ng-model="files" ngf-multiple="multiple">Select File</button>
Files:
<ul>
<li ng-repeat="f in files" style="font:smaller">{{f.name}}</li>
</ul>
Upload Log:
<pre>{{log}}</pre>
This is controller code.
这是控制器代码。
$scope.$watch('files', function () {
$scope.upload($scope.files);
});
$scope.log = '';
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
Upload.upload({
url: '/cgi-bin/upload.pl',
fields: {
'username': $scope.username
},
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$scope.log = 'progress: ' + progressPercentage + '% ' +
evt.config.file.name + '\n' + $scope.log;
}).success(function (data, status, headers, config) {
$timeout(function() {
$scope.log = 'file: ' + config.file.name + ', Response: ' + JSON.stringify(data) + '\n' + $scope.log;
});
})
.error(function (data, status, headers, config) {
alert ('Error');
});
}
}
};
This is Perl script.
这是Perl脚本。
#!c:/perl64/bin/perl.exe
use strict;
use warnings;
use DBI;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use CGI;
use CGI qw(:standard);
use JSON;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;
#send the obligatory Content-Type
print "Content-Type: text/html\n\n";
$CGI::POST_MAX = 1024 * 5000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $cgi = new CGI();
my $upload_dir = "../images"; #location on our server
my $filename = "dummy.png";
my $upload_filehandle = $cgi->upload("file");
print $upload_filehandle;
open UPLOADFILE, ">../..$upload_dir$filename" or die $!;
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
When i trying to upload the file on local Apache server, seeing this error.
当我尝试在本地Apache服务器上传文件时,看到此错误。
No such file or directory at C:/Program Files (x86)/Apache Group/Apache2/htdocs/admin/cgi-bin/upload.pl line 26.
在C:/ Program Files(x86)/ Apache Group / Apache2 / htdocs / admin / cgi-bin / upload.pl第26行没有这样的文件或目录。
This is line 26 in perl script.
这是perl脚本中的第26行。
open UPLOADFILE, ">../..$upload_dir$filename" or die $!;
I have a folder named images already created. So why this error?
我有一个名为images的文件夹已经创建。那么为什么这个错误?
Can anyone help me what is wrong, and what chages are needed to that i can upload the file properly.
任何人都可以帮我解决错误,以及需要什么样的格式才能正确上传文件。
1 个解决方案
#1
1
$upload_dir
is ../images
, and $filename
is dummy.png
, so "../..$upload_dir$filename"
is ../..../imagesdummy.png
.
Need I say more?
$ upload_dir是../images,$ filename是dummy.png,所以“../..$upload_dir$filename”是../..../imagesdummy.png。需要我多说?
That's why it's good to include the path in the error message.
这就是为什么在错误消息中包含路径是好的。
my $qfn = "../..$upload_dir$filename";
open(my $UPLOADFILE, '>', $qfn)
or die("Can't create \"$qfn\": $!\n");
(Note that I made other improvements, including switching from global glob UPLOADFILE
to lexical scalar $UPLOADFILE
for the file handle. You'll have to adjust the following code to use that scalar if you adopt this highly recommended practice.)
(请注意,我做了其他改进,包括从文件句柄的全局glob UPLOADFILE切换到词法标量$ UPLOADFILE。如果你采用这种强烈推荐的做法,你将不得不调整以下代码来使用该标量。)
#1
1
$upload_dir
is ../images
, and $filename
is dummy.png
, so "../..$upload_dir$filename"
is ../..../imagesdummy.png
.
Need I say more?
$ upload_dir是../images,$ filename是dummy.png,所以“../..$upload_dir$filename”是../..../imagesdummy.png。需要我多说?
That's why it's good to include the path in the error message.
这就是为什么在错误消息中包含路径是好的。
my $qfn = "../..$upload_dir$filename";
open(my $UPLOADFILE, '>', $qfn)
or die("Can't create \"$qfn\": $!\n");
(Note that I made other improvements, including switching from global glob UPLOADFILE
to lexical scalar $UPLOADFILE
for the file handle. You'll have to adjust the following code to use that scalar if you adopt this highly recommended practice.)
(请注意,我做了其他改进,包括从文件句柄的全局glob UPLOADFILE切换到词法标量$ UPLOADFILE。如果你采用这种强烈推荐的做法,你将不得不调整以下代码来使用该标量。)