请帮助!
我有一个图像上传器,除了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>
答案 0 :(得分:0)
我使用jquery和html格式
包含所有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>