如何在Windows弹出窗口的perl上获取文件名?
我正在使用 json 打开用户弹出窗口。 我曾经在 php 上使用 basename( $_FILES['userfile']['name'] )
,如何在 perl 上做到这一点?
服务器端代码:
#!/usr/bin/perl
use CGI;
print "Content-type: text/html;
Cache-Control: no-cache;
charset=utf-8\n\n";
@allowedExtensions =("jpg","tiff","gif","eps","jpeg","png");
my $q = CGI->new();
my $filename = $q->upload('userfile');
print "file name is $file_name";
客户端代码:
var post_obj = new Object();
new AjaxUpload('upload_attachment_button', {
action: 'upload.cgi',
type: "POST",
data: post_obj,
onChange: function() {},
onSubmit: function() {
$("#upload_attachment_button").addClass('ui-state-disabled');
$("#upload_proj_message").html('<span> class="loading">uploading...</span>');
},
onComplete: function(file, response) {
$("#upload_attachment_button").removeClass('ui-state-disabled');
alert(response);
}
});
I'm using json to open the user popup.
I used to use basename( $_FILES['userfile']['name'] )
on php, how to do that on perl?
Server side code:
#!/usr/bin/perl
use CGI;
print "Content-type: text/html;
Cache-Control: no-cache;
charset=utf-8\n\n";
@allowedExtensions =("jpg","tiff","gif","eps","jpeg","png");
my $q = CGI->new();
my $filename = $q->upload('userfile');
print "file name is $file_name";
Client side code:
var post_obj = new Object();
new AjaxUpload('upload_attachment_button', {
action: 'upload.cgi',
type: "POST",
data: post_obj,
onChange: function() {},
onSubmit: function() {
$("#upload_attachment_button").addClass('ui-state-disabled');
$("#upload_proj_message").html('<span> class="loading">uploading...</span>');
},
onComplete: function(file, response) {
$("#upload_attachment_button").removeClass('ui-state-disabled');
alert(response);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在尝试获取用户上传的文件的名称。如果您使用的是
CGI
模块,那么这里是解决方案:来自 手册:
更新:
抱歉,之前没注意到。请在脚本开头添加
use strict;
。它会强制您声明所有变量。您会在print
语句中看到错误:要声明
@allowedExtensions
只需在首次使用之前添加my
:另外我相信您不需要打印 HTTP 标头时在行尾添加
;
:并且请始终
使用 strict
。它将在未来为您节省大量时间。Looks like you trying to get name of the file uploaded by user. If you are using
CGI
module, then here is solution:From the manual:
Update:
Sorry, didn't noticed it before. Please add
use strict;
at the begining of the script. It'll force you to declare all variables. You'll see mistype inprint
statement:To declare
@allowedExtensions
just addmy
before first use:Also I believe that you don't need
;
at the end of lines when you print HTTP headers:And please always
use strict
. It'll save you tons of time in future.