0

请帮忙!

我有一个图像上传器,它似乎在除 IE 之外的所有浏览器中都运行良好 :(

它似乎只是被加载的 GIF 卡住了,什么也不做。可能是上面的代码还是实际上传页面中的 JavaScript?

有什么建议么?...

<?php
session_start();
include 'resizeimage.php';
include '../conf/config.php';
$loggedin = $_SESSION['loggedin_user'];
$getmid = mysql_query("SELECT * FROM members WHERE Username = '$loggedin'");
while($iamid = mysql_fetch_array($getmid))
{
$member_id = $iamid['ID'];
}
$path = "../m/members_image/".$member_id."/temp/";
$valid_formats = array("jpg", "jepg", "png", "gif", "pjpeg", "pjpg", "PJPEG", "PJPG", "JPG", "JPEG", "PNG", "GIF");
$pid = date("Ymdhis");
$pid = str_replace(".", "", "$pid");
$pid = $member_id;
/*$_SESSION['pid'] = $pid;*/
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name)) {
$extarr = explode(".", $name);
$ext = end($extarr);
if(in_array($ext,$valid_formats)) {
if($size<(3000000)) {
$actual_image_name = $pid.".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, "$path$actual_image_name")) {
$imgsrc = "$path$actual_image_name";
list($width, $height) = getimagesize($imgsrc);
$image = new SimpleImage();
$image->load($imgsrc);
if ( $width > $height ) { $image->resizeToWidth(960); }
else { $image->resizeToHeight(600); }
$image->save("$imgsrc");
list ($width1, $height1) = getimagesize($imgsrc);
if ( $width1 > 960 ) {
$image->resizetoWidth(960);
$image->save("$imgsrc");
} else {}
if ( $height1 > 600 ) {
$image->resizetoHeight(600);
$image->save("$imgsrc");
} else {}
echo "<img class='preview'>";
} else { echo "failed"; };
} else { echo "Image file size max 3 MB"; }
} else { echo "Invalid file format.."; }
} else { echo "Please select image..!"; }
exit;
}
?>

JavaScript:

<script type="text/javascript" >

$(document).ready(function() { 

$('#photoimg').live('change', function() { 

    $("#btn_contaier_browse").hide();
    $("#preview").html('');
    $("#preview").html("<div class='splittermessages'></div><br><table border='0'><tr><td><img width=60 src='/images/loading.gif'></td><td>Uploading image ..</td></tr></table>");

    $("#imageform").ajaxForm({
        target: '#preview', 
        success: showCrop

    }).submit();
});
});
function showCrop() {
$("#btn_contaier_browse").show();
$("#tiltusm").html('Make thumbnails.. crop your image');
$('#currentElement').attr("src", $('#currentElement').attr("src"));
$("#currentElement").css("display","block");
$('#currentElement').hide();
$('#currentElement').fadeIn(500);

}
function reloadz() {

setTimeout(function(){ window.location = '/photos.html';}, 3000); 

}
</script>
4

1 回答 1

0

我使用带有 html 表单的 jquery

包括所有的 jquery 文件然后使用下面的代码

html

<head>
$(function() {
    $('#submitBtn').bind('click', function(e) {
        $('#myForm').submit();
        $('#myFrame').live('change', function(e) {
             //read iframe and put your own success message
        });
    });
});
</head>
<body>
<form id="myForm" action="myAction.php" enctype="multipart/formdata" target="myFrame">
<input id="file" type="file" />
<input type="submit" id="submitBtn" />
</form>
<iframe id="myFrame" name="myFrame" ></iframe>
</body>
于 2013-05-08T18:36:02.867 回答