上传表单上传了一些.jpeg图片而不是其他图片

时间:2013-06-17 22:29:15

标签: php image forms upload

热门编辑: 我想到了。一切都很好,唯一的问题是代码告诉图像去的上传文件夹是错误的。我所要做的就是在目标文件夹上的“照片”之前插入一个斜杠。它在我的本地机器上工作的原因一定是由于自动添加了斜线或者某些东西......无论如何,一旦我修复它,它就像一个魅力 - 无论我使用什么样的.jpg图像:)

您知道吗,如果您遇到uploadify问题 - 使用调试功能:'debug':true, - 这就是我能够看到它试图将文件放在错误的文件夹中的方式 - 我我不知道如何解决这个问题。

原始问题: 我有一个PHP上传系统工作,我可以允许用户上传图像或多个图像到网站。然后网站接收它们,创建缩略图,然后将它们和拇指存储在一个文件夹中。

它适用于一些jpeg图像,但是有一些jpeg图像(它们都是转换为jpeg的原始文件是相关的)不起作用。

有没有人听说过这个 - 莫名其妙。最大上传大小,一切都很好。这是一个奇怪的问题。

谢谢!

编辑: 这是代码。我现在已经改变了我的系统以尝试实现Uploadify,虽然它可以在我的本地服务器上运行,但是当我把它放到实时时它不起作用:(。它上传到数据库,但不上传实际的图像:)

我不知道如果它的文件权限有什么问题(怀疑它 - 因为我以前能够上传)或某种时间。问题是uploadify代码表示它完成了任务,并且除了放入实际图像之外它做的一切正确:)

我不知道为什么这不起作用。

这是add_pic页面(将信息发送到uploadify)     

ini_set('max_execution_time', 400); // this way images can be uploaded without the server timing out.

if(!logged_in()){// if the user is not logged in
    require_once 'php/header.php';
    echo '<br>You are not logged in, please navigate to the <a href="login.php" title="Login Page">login page</a> in order to get logged in.<br>';// let the user know
    require_once 'php/footer.php';// include footer
    exit();// kick the user out
}

if(!permission()){// if the user does not have permission to be here
    require_once 'php/header.php';
    echo '<br>You do not have permission to view this page, please return to the <a href="profile.php" title="Profile Page">profile page</a>.<br>';// let the user know
    require_once 'php/footer.php';// include footer
    exit();// kick the user out
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="author" content="Josh Menzies - Trillium Webpage Design">
        <meta charset='utf-8'>
        <title>Dan McCracken Photography | Add Picture</title>
        <script src="js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
        <script type="text/javascript" src="js/validate.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
        <script src="jquery.uploadify.min.js" type="text/javascript"></script>
        <link href="css/css.css" media="screen" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="uploadify.css">
    </head>
        <body>
            <div id="wrap">
                <div id="header">
                    <header>
                        <a href="index.php" title="Home Page"><img src="css/images/DanMcCracken-logo-noline.jpg" alt="Logo Image"></a>
                        <!-- Header content here -->
                        <?php include_once("php/toolbar.php"); ?>
                        <span class="line">&nbsp;</span>
                    </header>
                </div><!-- end div header -->
                <div id="main">
<script type="text/javascript">
    var request = ''; // the request tracking variable
    $(document).ready(function() {
        $('#add_album_drop_down_input').change(function(){
            var data = $(this).val();

            if(request != '') return false;
            var data = 'album='+data;
            if(data != ''){

                request = $.ajax({
                    //this is the php file that processes the data and send mail
                    url: 'update_session.php',  
                    //GET method is used
                    type: "POST",
                    //pass the data         
                    data: data,     
                    //Do not cache the page
                    cache: false,
                    //on success -> handler function
                    // html = html data returned from the other page by echo
                    success: function (html) {
                        request = '';
                        //if html data is present
                        if (html != 0) {
                        }
                        else alert('2 Sorry, unexpected error. Please try again later. Error: ');               
                    }   
                });
            }

            return false;

        });
    }); 
</script>
<?php
    $dbc = mysqli_connect(HOST, USER, PASS, DBNAME);
        $query = "SELECT id, name FROM album";
        $result = mysqli_query($dbc, $query);
    mysqli_close($dbc);
?>
    <form>
        <fieldset form="add_pic_form" id="add_pic_choose_album_fieldset" name="add_pic_choose_album_fieldset" class="one">
        <legend>Choose Album</legend>
            <select id="add_album_drop_down_input" name="add_album_drop_down_input" form="add_pic_form">
            <?php
                            if(isset($_GET['id']) && !empty($_GET['id']) && isset($_GET['id']) && !empty($_GET['name'])){
                                ?>
                                <option value="<?php echo $_GET['id'].'_'.$_GET['name'];?>">
                                    <?php echo $_GET['name'];?>
                                </option>
                                <?php
                            }
                            else{
                                ?>
                                <option value="">-- Please Select --</option>
                            <?php
                            }
                                while($row = mysqli_fetch_array($result)){
                                    echo '<option value="'.$row['id'].'_'.$row['name'].'">
                                '.$row['name'].'
                                </option>';
                }
                            ?>
            </select>
            </fieldset>
        <div id="queue"></div>
        <input id="file_upload" name="file_upload" type="file" multiple class="file_upload">
    </form>

    <script type="text/javascript">
        <?php $timestamp = time();?>
        $(function() {
            $('#file_upload').uploadify({
                'formData'     : {
                    'timestamp' : '<?php echo $timestamp;?>',
                    'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
                },
                'swf'      : 'uploadify.swf',
                'uploader' : 'uploadify.php',
                'buttonText' : '+ Add Images',
                'fileSizeLimit' : '2MB'
            });
        });
    </script>
                </div>
            </div>
</body>
</html>

这是处理代码的uploadify页面

<?php require_once 'php/startsession.php';// start the session
require 'php/connectvars.php';
require 'php/functions.php';
error_reporting(0);

ini_set('max_execution_time', 400); // this way images can be uploaded without the server timing out.

if(!logged_in()){// if the user is not logged in
    require_once 'php/header.php';
    echo '<br>You are not logged in, please navigate to the <a href="login.php" title="Login Page">login page</a> in order to get logged in.<br>';// let the user know
    require_once 'php/footer.php';// include footer
    exit();// kick the user out
}

if(!permission()){// if the user does not have permission to be here
    require_once 'php/header.php';
    echo '<br>You do not have permission to view this page, please return to the <a href="profile.php" title="Profile Page">profile page</a>.<br>';// let the user know
    require_once 'php/footer.php';// include footer
    exit();// kick the user out
}

/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
 * Page modified in June of 2013 by Josh Menzies of Trillium Webpage Design
*/

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

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if( isset($_SESSION['album']) && !empty($_SESSION['album']))
    {
        $album_data = explode('_',$_SESSION['album']);
        $album_id = $album_data[0];
        $album_name = $album_data[1];
    }
    else echo'Album not selected.';

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder.'/'.$album_name.'_'.$album_id;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; //the file name
    $targetThumb = rtrim($targetPath,'/') . '/thumb_' . $_FILES['Filedata']['name']; //the thumb name

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

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile); // move file
        create_thumb(160,$targetFile,$targetThumb);// create thumb of file
        // add file to database
        $dbc = mysqli_connect(HOST, USER, PASS, DBNAME);// open the database connection
            $query = "INSERT INTO image (album_id, name) VALUES ('$album_id', '".$_FILES['Filedata']['name']."');";
            $result = mysqli_query($dbc, $query);
        mysqli_close($dbc);// close the database that we opened

        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}
?>

更新会话页面(更新会话变量以传递信息

<?php require_once 'php/startsession.php';// start the session
require 'php/connectvars.php';
require 'php/functions.php';
error_reporting(0);

if(!logged_in()){// if the user is not logged in
    require_once 'php/header.php';
    echo '<br>You are not logged in, please navigate to the <a href="login.php" title="Login Page">login page</a> in order to get logged in.<br>';// let the user know
    require_once 'php/footer.php';// include footer
    exit();// kick the user out
}

if(!permission()){// if the user does not have permission to be here
    require_once 'php/header.php';
    echo '<br>You do not have permission to view this page, please return to the <a href="profile.php" title="Profile Page">profile page</a>.<br>';// let the user know
    require_once 'php/footer.php';// include footer
    exit();// kick the user out
}


    if(isset($_POST['album']) && !empty($_POST['album'])){
        $_SESSION['album'] = $_POST['album'];
        echo 1;
    }
    else echo 0;

?>

这是缩略图代码:

function create_thumb($width,$image,$destination,$quality = 100)
{   
    list($old_width, $old_height) = getimagesize($image);// get the dimensions of the image
    $ratio = ($width / $old_width);
    $new_width = $width;
    $new_height = ($old_height * $ratio);
    $thumb = imagecreatetruecolor($new_width, $new_height);// create a blank thumb image
    $source = imagecreatefromjpeg($image);// get the old image?
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);// copy the old image over into the new dimensions
    // output the image with the appropriate name
    if(imagejpeg($thumb, $destination, $quality)) return true;
    else return false;
    return true;
}

0 个答案:

没有答案