Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Uploadify脚本没有错误,但也没有上载_Javascript_Jquery_Uploadify - Fatal编程技术网

Javascript Uploadify脚本没有错误,但也没有上载

Javascript Uploadify脚本没有错误,但也没有上载,javascript,jquery,uploadify,Javascript,Jquery,Uploadify,我使用uploadify,我的问题是文件没有上传 这是我的代码: 在uploadify.php上,我已将根路径设置为:/ 像这样: $targetFolder = '/'; // Relative to the root 然后,脚本上的其余部分: <script type="text/javascript"> jQuery(document).ready(function() { $('#file_upload').uploadify({ 'uploa

我使用uploadify,我的问题是文件没有上传

这是我的代码:

在uploadify.php上,我已将根路径设置为:/

像这样:

$targetFolder = '/'; // Relative to the root
然后,脚本上的其余部分:

<script type="text/javascript">
jQuery(document).ready(function() {


     $('#file_upload').uploadify({
        'uploader'    : '/myIncludes/UploadiftyFolder/uploadify.php',
        'swf'  : '/myIncludes/UploadiftyFolder/uploadify.swf',
        'cancelImg' : '/myIncludes/UploadiftyFolder/cancel.png',
        'folder'    : '/myUploads/UploadsDirectory/images/',
        'auto'      : true,
        'multi'         : false,
        'checkExisting' : false
      });
});
</script>

//Finally 

<input id="file_upload" type="file" name="Filedata" />
<a href="javascript:$('#file_upload').uploadifyUpload();">Upload Files</a>
下面是uploadify.php文件的其余部分。。。我没有改变任何事情:

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

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}
尝试在上载文件夹之前提供“~/”

(或)以下是整个脚本:

<script type="text/javascript">
    $(window).load(
function () {
    $("#fileInput1").uploadify({
        'uploader': 'scripts/uploadify.swf',
        'cancelImg': 'images/cancel.png',
        'buttonText': 'Browse Files',
        'script': 'UploadVB.ashx',
        'folder': 'uploads',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'queueSizeLimit': 9999,
        'simUploadLimit': 2,
        'sizeLimit': 4000000,
        'multi': true,
        'auto': true,
        'onComplete': function (event, queueID, fileObj, response, data) {
                        $("#thumbnail").append(response)

        },

        'onError': function (event, ID, fileObj, errorObj) {
            alert(errorObj.type + ' Error: ' + errorObj.info);
        }


    });
}
);
</script>

$(窗口)。加载(
函数(){
$(“#文件输入1”)。上载({
'uploader':'scripts/uploadify.swf',
'cancelImg':'images/cancel.png',
'buttonText':'Browse Files',
'script':'UploadVB.ashx',
'文件夹':'上载',
'fileDesc':'Image Files',
“fileExt”:“*.jpg;*.jpeg;*.gif;*.png”,
'queueSizeLimit':9999,
“simUploadLimit”:2,
“sizeLimit”:4000000,
"多":对,,
“自动”:正确,
“onComplete”:函数(事件、队列ID、fileObj、响应、数据){
$(“#缩略图”).append(响应)
},
“onError”:函数(事件、ID、fileObj、errorObj){
警报(errorObj.type+'Error:'+errorObj.info);
}
});
}
);

对我来说,问题出在
uploadify.php
文件中。他们正在使用:

$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
$targetFolder
由您在顶部定义

后来:

move_uploaded_file($tempFile,$targetFile);
默认示例将目标文件夹附加到
$\u SERVER['DOCUMENT\u ROOT']
的末尾。我的
$\u服务器['DOCUMENT\u ROOT']
实际上是
C:\xampp\htdocs
。因此,要使其正常工作,您的目标文件夹必须是:

$targetFolder=“/yourSiteFolder/where/your/upload/folder/is”

我所做的:

完全摆脱了
$\u服务器['DOCUMENT\u ROOT']
。这是我的
uploadify.php
文件:

<?php
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
//$targetFolder = '/sandbox/uploads'; // Relative to the root

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

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}
?>
<?php
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
//$targetFolder = 'uploads'; // Relative to the root and should match the upload folder     in the uploader script

if (file_exists("uploads/" . $_POST['filename'])) {
    echo 1;
} else {
    echo 0;
}
?>
为此:

move_uploaded_file($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]);
然后注释掉了几行不再需要的内容

这是我的
检查exists.php
文件:

<?php
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
//$targetFolder = '/sandbox/uploads'; // Relative to the root

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

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($_FILES["Filedata"]["tmp_name"], "uploads/" . $_FILES["Filedata"]["name"]);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}
?>
<?php
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
//$targetFolder = 'uploads'; // Relative to the root and should match the upload folder     in the uploader script

if (file_exists("uploads/" . $_POST['filename'])) {
    echo 1;
} else {
    echo 0;
}
?>
关于我的网站的文件结构的说明:

所有uploadify文件都位于我的站点根目录下的一个名为
uploadify
的文件夹中。在
uploadify
中有一个名为
uploads
的文件夹,这是上传文件的地方


希望这能有所帮助。

对我来说,我所要做的就是去掉$targetPath定义中的$\u SERVER['DOCUMENT\u ROOT']。然后我还使用了“上传”而不是“/uploads”作为我的$targetFolder。

我在这里尝试了所有其他建议,但没有一个对我有效。然后我意识到Uploadify的3.2版(也可能是以前的版本)需要时间戳和哈希标记才能完成上传

首先,我必须将脚本从外部JS文件移动到我的PHP文件中,以便从PHP中获取时间戳。(您也可以通过隐藏的输入值或其他方法来实现这一点,但这是最简单的方法。)然后,我必须向Uploadify调用中添加一些PHP代码,这些代码获取时间戳并使用唯一的salt(您应该将其改为随机字符串)对其进行哈希:


$('#文件上传')。上传({
“swf”:“/uploadify/uploadify.swf”,
“uploader”:“/uploadify/uploadify.php”,
“formData”:{
“时间戳”:“,
“令牌”:”
}
});

虽然3.2版中似乎需要此代码,但本手册中未提及此代码。我必须查看下载包中的index.php文件才能找到它。

Im使用php上传程序。。所以……”上传程序“:”/files/uploadify.php“。。。但是我已经添加了你的oncomplete和onerror,但是我没有得到任何回报。这只是所需上传文件夹的问题。请确保uploadify.php中的上传文件夹的引用路径正确
<?php
/*
Uploadify v3.1.0
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
//$targetFolder = 'uploads'; // Relative to the root and should match the upload folder     in the uploader script

if (file_exists("uploads/" . $_POST['filename'])) {
    echo 1;
} else {
    echo 0;
}
?>
$(function() {
    $("#uploadify").uploadify({
        height        : 30,
        swf           : 'uploadify/uploadify.swf',
        uploader      : 'uploadify/uploadify.php',
        width         : 120
    });
});
<?php $timestamp = time();?>
<script>
$('#file_upload').uploadify({
    'swf'      : '/uploadify/uploadify.swf',
    'uploader' : '/uploadify/uploadify.php',
    'formData' : {
        'timestamp' : '<?php echo $timestamp;?>',
        'token'     : '<?php echo md5("unique_salt" . $timestamp);?>'
    }
});
</script>