我想使用php和jcrop在方形裁剪后在mysql上传图像。
我有这种类型的代码,但它并没有让plz帮助我......
HTML
<form name="upload.php" enctype="multipart/form-data" action="" method="post"class="frmImageUpload">
<label>Profile Picture:</label><br/>
<img id="blah" class="crop" src="pro.png" style="width:500px;maxwidth:500px;height:width;max-height:500px;" border="1" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<div class="file_button_container">
<input name="userImage" type="file" id="userImage" /></div>
<input type="submit" value="Upload" class="btnSubmit" />
</from>
脚本
<script type='text/javascript' src="http://jcropcdn.tapmodo.com/v0.9.12/js/jquery.Jcrop.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://jcropcdn.tapmodo.com/v0.9.12/css/jquery.Jcrop.min.css">
<style type='text/css'>
#blah {
background-color: #000;
width: 500px;
font-size: 24px;
display: block;
}
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
$('.crop').Jcrop({
onSelect: updateCoords,
bgOpacity: .4,
setSelect: [ 500, 10, 10, 10 ],
aspectRatio: 16 / 16
});
}
reader.readAsDataURL(input.files[0]);
}
}
$("#userImage").change(function(){
console.log(this);
readURL(this);
});
function updateCoords(c)
{
console.log(c);
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
});//]]>
</script>
Upload.PHP(我想,这不行)
<?php
$max_file_size = 1000 * 1024;
if(count($_FILES) > 0) {
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
if (! $_FILES['image']['error'] && $_FILES['image']['size'] < $max_file_size) {
$conn = mysql_connect("LOCAL", "USERNAME", "PASSWORD");
mysql_select_db("DB NAME");
$nw = $nh = 200;
$x = (int) $_POST['x'];
$y = (int) $_POST['y'];
$w = (int) $_POST['w'] ? $_POST['w'] : $size[0];
$h = (int) $_POST['h'] ? $_POST['h'] : $size[1];
$data = addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
$vImg = imagecreatefromstring($data);
$dstImg = imagecreatetruecolor($nw, $nh);
$imgData = imagecopyresampled($dstImg, $vImg, 0, 0, $x, $y, $nw, $nh, $w, $h);
$imageProperties = getimageSize($_FILES['userImage']['tmp_name']);
$imgt = $imageProperties['mime'];
$stet = $_POST['stet'];
$sql ="UPDATE users SET
imageType='$imgt',
imageData='$imgData',
stet='$stet'
WHERE id=" . $_SESSION['user']['id'];
$current_id = mysql_query($sql) or die("<b>Error:</b> Problem on Image Insert<br/>" . mysql_error());
if(isset($current_id)) {
header("Location: index.php");
}
}
else
{
echo 'file is too small or large';
}
}}
?>
这段代码有什么问题,plz很快就让我失望
我想在jcrop使用php之后将图像存储在MySQL BLOB中。