|
test_picture = function() {
api.getPicture({
sourceType: 'library',
encodingType: 'png',
mediaValue: 'pic',
destinationType: 'url',
allowEdit: true,
//quality: 50,
//targetWidth:100,
//targetHeight:100,
saveToPhotoAlbum: false
}, function(ret, err){
if (ret) {
api.ajax({
timeout : 100,
method : 'post',
url : 'http://192.168.1.121/picture.php',
data : {
files:{upfile : ret.data},
},
dataType : 'json',
}, function(ret, err) {
api.hideProgress();
alert(JSON.stringify(ret));
});
} else {
api.alert({msg:err.msg});
};
});
};
PHP接收图片
<?php
function getname($exname){
$dir = "./uploadfile/";
$i=1;
if(!is_dir($dir)){
mkdir($dir,0777);
}
while(true){
if(!is_file($dir.$i.".".$exname)){
$name=$i.".".$exname;
break;
}
$i++;
}
return $dir.$name;
}
$exname=strtolower(substr($_FILES['upfile']['name'],(strrpos($_FILES['upfile']['name'],'.')+1)));
$uploadfile = getname($exname);
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) {
echo "<h2><font color=#ff0000>文件上传成功!</font></h2><br><br>";
} else {
echo "<h2><font color=#ff0000>文件上传失败!</font></h2><br><br>";
}
?>
|
|