1

我知道之前已经回答了这个问题,但是其他帖子上的解决方案对我不起作用。尝试上传时,我在 uploadify 框中收到 HTTP 错误 (404)。

这是我的uploadify相关代码:head:

<link rel="stylesheet" type="text/css" href="js/uploadify/uploadify.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/uploadify/jquery.uploadify-3.1.min.js"></script>

身体:

<input type="file" name="file_upload" id="file_upload" />

文件准备就绪:

$('#file_upload').uploadify({
                    'swf'      : 'js/uploadify/uploadify.swf',
                    'uploader' : 'js/uploadify/uploadify.php' ,
                    'cancelImg' : 'js/uploadify/cancel.png',
                    'multi'      : false,
                    'buttonText' : 'Add main picture'
                });

上传.php:

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

// Define a destination
$targetFolder = 'C:/xampp/htdocs/site/sites_images/'; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $targetFolder;
    $targetFile = $targetFolder . $_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.';
    }
}

我错过了什么?

4

0 回答 0