dsvyc66464 2010-09-04 22:07
浏览 48
已采纳

无法使用Uploadify脚本上传文件

I am using the Uploadify Plugin to Upload files. although this might be a very basic question i am unable to understand and implement to get it work to upload the files.

I want to achieve the following using uploadify

when a user select the file i want it to be directly uploaded to the target path using PHP.

now i am using the following code.

<html>
<head>
<link rel="stylesheet" href="css/uploadify.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.uploadify.v2.1.0.min.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
</head>

<script type="text/javascript">
$(document).ready(function() {
    $('#someID').uploadify({ 
      'uploader': 'img/uploadify.swf',
      'script': 'uploadify.php',
      'folder': 'upload',
      'cancelImg': 'img/cancel.png',
      'auto': 'true',
      'fileDesc': 'jpg/jpeg',
      'displayData': 'percentage',
      'fileExt': "*.jpg;*.jpeg",
      'sizeLimit' : '8388608'
      }); }); 
      </script>

<body>
<form id="someID" action="uploadify.php" method="post" enctype="multipart/form-data"> 
<input type="file" name="file" id="fileUpload1"/>
<p><input type="submit" name="submit" value="Upload" /></p> 
</form>
</body>

and this is the code for uploadify.php

if (!empty($_FILES)) {
    $tempFile = $_FILES['file']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['file']['name'];
    move_uploaded_file($tempFile,$targetFile);
        echo "1";

I just want to upload a single file. do i need to include the check.php for that. how do i make something like when a user select the image file it directly performs the operation and move to the designated directory.

P.S: I have the very basic understanding of javascript and jquery. :)

Note : file uploading problem is solved now.

how do i limit the user from uploading just one file on one button, i want something like when a user select the file and it gets uploaded that button should be disabled or something

EDIT : for limiting the users from uploading multiple file in a button i added this code and it is still uploading many files as and when users select multiple times. here is my code.

<script type="text/javascript">
$(document).ready(function() {
    $('#someID').uploadify({ 
      'uploader': 'img/uploadify.swf',
      'script': 'uploadify.php',
      'folder': 'upload',
      'cancelImg': 'img/cancel.png',
      'auto': 'true',
      'fileDesc': 'jpg/jpeg',
      'displayData': 'percentage',
      'fileExt': "*.jpg;*.jpeg",
      'sizeLimit' : '8388608',
      'fileDataName' : 'file',
      onSelect : function(){
           $("#someID input").attr("disabled", true);
      }
      }); }); 
      </script>

what is wrong with it?

  • 写回答

2条回答 默认 最新

  • dsgawmla208057 2010-09-04 22:10
    关注

    I was wrangling with this a few weeks ago. You need to change your fileDataName attribute. By default, it is Filedata. You are trying to access it as file in this part: $_FILES['file'].

    Either change all instances of $_FILES['file'] to $_FILES['Filedata'] or add this attribute to your $('#someID').uploadify({}); attribute collection: fileDataName:'file'.

    If you are looking for a drop-in fix, just make this change in your JavaScript:

    $(document).ready(function() {
        $('#someID').uploadify({ 
          'uploader': 'img/uploadify.swf',
          'script': 'uploadify.php',
          'folder': 'upload',
          'cancelImg': 'img/cancel.png',
          'auto': 'true',
          'fileDesc': 'jpg/jpeg',
          'displayData': 'percentage',
          'fileExt': "*.jpg;*.jpeg",
          'sizeLimit' : '8388608',
          'fileDataName' : 'file'
          }); 
    }); 
    

    Note the 'fileDataName' : 'file'

    To limit a single upload (as long as the page isn't refreshed, of course):

    Change your JavaScript to this:

    $(document).ready(function() {
        $('#someID').uploadify({ 
          'uploader': 'img/uploadify.swf',
          'script': 'uploadify.php',
          'folder': 'upload',
          'cancelImg': 'img/cancel.png',
          'auto': 'true',
          'fileDesc': 'jpg/jpeg',
          'displayData': 'percentage',
          'fileExt': "*.jpg;*.jpeg",
          'sizeLimit' : '8388608',
          onSelect : function(){
               $("#someID input").attr("disabled", true);
          }}); 
    }); 
    

    Just know that if the user refreshes the page, the button will be enabled again allowing them to upload another file. They can also re-enable it manually. So, add a server-side check to make sure that they don't upload another file if you don't want them to.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀