在Uploadify中使用scriptData发送php会话变量
我正在使用 uploadify 上传文件,我想根据单选按钮的值将其存储在文件夹中。我有多个文件夹,我希望用户使用单选按钮选择其中一个文件夹,然后上传文件。
使用单选按钮的值,我将决定文件夹,并且我还想将用户 ID 附加到上传的文件中。如何将单选按钮 #type.val() 和 _SESSION['id'] 的值发送到 uploadify.php
我尝试这样做,但它不起作用
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads/operatingSystem',
'auto' : true,
'scriptData': {'type':''},
'onSelectOnce' : function(event,data) {
$("#file_upload").uploadifySettings('scriptData', {'type' : ('#topic').val()});
});
});
</script>
在此我仍然不知道如何给出会话 id因为这不起作用
'scriptData': {'type':'', 'id':''},
'onSelectOnce' : function(event,data) {
$("#file_upload").uploadifySettings('scriptData', {'type' : ('#topic').val(), 'id' : <?php echo $_SESSION['id']; ?> });
I am using uploadify to to upload a file and I want to store it in a folder depending on the value of a radio button. I have multiple folders and I want the user to select one of the folders using a radio button and then upload files.
Using the value of the radio button, I will decide the folder and I also want to append the user id to the uploaded file. How can I send the value of radio button #type.val() and _SESSION['id'] to the uploadify.php
I tried doing this but it doesn't work
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads/operatingSystem',
'auto' : true,
'scriptData': {'type':''},
'onSelectOnce' : function(event,data) {
$("#file_upload").uploadifySettings('scriptData', {'type' : ('#topic').val()});
});
});
</script>
In this I still do not know how to give the session id because this does not work
'scriptData': {'type':'', 'id':''},
'onSelectOnce' : function(event,data) {
$("#file_upload").uploadifySettings('scriptData', {'type' : ('#topic').val(), 'id' : <?php echo $_SESSION['id']; ?> });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常它应该可以工作,但是对于我的 PHP 5.3.8,如果我想使用会话变量,它的拼写是 $_SESSION 而不是 _SESSION。也许是语言问题?
Normally it should work but with my PHP 5.3.8 if I want to use the session variable it's spelled $_SESSION an not _SESSION. Maybe a language problem?
我有同样的问题,我们最近将开发服务器切换到 5.3,并且所有上传脚本都停止工作(使用我通过发布数据传递的 $_SESSION var。-> scriptData)。当我切换回 5.2 时,一切都很顺利。有些东西配置不正确,我还没弄清楚。
I have the same issue, we recently switched our development server to 5.3 and all upload scripts stopped working (using the $_SESSION var which i pass through the post data.-> scriptData). when i switch back to 5.2 everything works like charm. Something is not configured properly, and I haven't figured it out yet.
您可以通过 formData 轻松传递会话。这是一个示例代码:
JS 代码:
PHP 代码:
我希望它会有所帮助。
You can easily pass sessions by formData. Here is an example code:
JS Code:
PHP Code:
I hope it'll be helpful.