开发者

uploadify is tempermental? unable to list newly uploaded files in database!

开发者 https://www.devze.com 2022-12-18 06:35 出处:网络
i\'ve been trying to work the uploadify script to little avail... it uploads all the files correctly to the assigned folder but no details of the upload are added via mysql.

i've been trying to work the uploadify script to little avail... it uploads all the files correctly to the assigned folder but no details of the upload are added via mysql.

any idea of where i may be making a mistake? please help.

manage.php

  <script type="text/javascript"> 
    $(document).ready(function() {
        $("#uploadify").uploadify({
            'uploader'       : 'resources/uploadify.swf',
            'script'         : 'resources/uploadify.php',
            'folder'         : 'files',
            'queueID'        : 'fileQueue',
            'auto'           : true,
            'onAllComplete'  : function(){ alert("Thank you. All files have been uploaded successfully."); },
            'multi'          : true
        });
    });
    </script>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . '?id=' . intval($client_id); ?>">
    <p>
         <b>File Upload</b></p>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<p><a href="javascript:jQuery('#uploadify').uploadifyClearQueue()" class="form">Cancel all uploads</a></p>
<a href="#viewFiles" class="form" rel="facebox">View files</a>

<div id="viewFiles" style="display:none;" rel="facebox"> 
                   <div style="width:300px; height: 300px;"></div>
</div>

    </p>
</form>

uploadify.php

<?php require_once('../Connections/speedycms.php); 

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

    $fileName = $_FILES['uploadify']['name'];
    $fileSize = $_FILES['uploadify']['size'];
    $fileType = $_FILES['uploadify']['type'];

        $client_id = mysql_real_escape_string($_GET['id']);

    // $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes  = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts  = pathinfo($_FILES['Filedata']['name']);

    // if (in_array($fileParts['extension'],$typesArray)) {
        // Uncomment the following line if you want to make the directory if it doesn't exist
        // mkdir(str_replace('//','/',$targetPath), 0755, true);

        move_uploaded_file($tempFile,$targetFile);
        echo "1";

        mysql_query("
INSERT INTO tbl_accidentfiles SET client_id='$开发者_Python百科client_id', name='${fileName}', path='${targetFile}', size='$fileSize', content_type='${content_type}'");

    // } else {


//  echo 'Invalid file type.';
        // }

    }

?>

many thanks!


The flash script is calling the uploadify.php file and not the form on the manage.php page.

Try changing:

$fileName = $_FILES['uploadify']['name'];
$fileSize = $_FILES['uploadify']['size'];
$fileType = $_FILES['uploadify']['type'];

to:

$fileName = $_FILES['Filedata']['name'];
$fileSize = $_FILES['Filedata']['size'];
$fileType = $_FILES['Filedata']['type'];


Maybe a php error? First line...

<?php require_once('../Connections/speedycms.php); 

(missing single quote), needs to be...

<?php require_once('../Connections/speedycms.php'); 

This would expalin why mysql_query doesn't run as the database connection wouldn't be set up


Your code have some error, since in uploadify.php you have:

$client_id = mysql_real_escape_string($_GET['id']);

But you haven't pass it in the uploadify js code. To do it, use this code:

$("#uploadify").uploadify({
  'uploader'       : 'resources/uploadify.swf',
  'script'         : 'resources/uploadify.php',
  'folder'         : 'files',
  'queueID'        : 'fileQueue',
  'auto'           : true,
  'onAllComplete'  : function(){ alert("Thank you. All files have been uploaded successfully."); },
  'multi'          : true,
  scriptData       : {'id': '<?php echo intval($client_id); ?>'}
});

In the latest uploadify, the default method for scripData is POST. So, use $_POST['id'] in your uploadify.php file, or change the method in uploadify js:

'method' : 'GET'

See here for more complete parameter. I hope it worked now.

Last note, in uploadify.php you can do this instead:

$client_id = intval($_GET['id']);

to make sure that client_id contain a valid value. It's better than just escape it, because you make sure it only contain integer, not other value.


Thanx for the post. Actually my client needs to upload number of images for a tour package.and i wanted to save them in the database. For this I have to use multiple uploader. so i decided to create a separate table for images linked via common package ID. I got an idea to insert the table with image and respective id field

Than you

0

精彩评论

暂无评论...
验证码 换一张
取 消