【发布时间】:2013-12-06 23:44:41
【问题描述】:
编辑: 它确实更新了,但延迟了几个小时..
另一个编辑;
它只发生在我的 nexus 4 上,我今天在我的 SGS1 上测试了它,它可以正常工作。 可能是什么问题?
你可以说它有点复杂,所以请仔细阅读:
我有一个将图像上传到网络的应用程序,(图像可以是任何东西,来自用户的设备)。
我现在为该结构添加了一个编辑功能,如果用户想更改旧图像,还可以在其中上传新图像。
确实有效。我通过浏览器对其进行了测试,服务器上的图像确实发生了变化。
但另一方面,在应用程序上,由于某种原因它没有(图像没有改变,即使服务器上的图像现在已经改变并且之前的图像不存在了。 )。
就像,它被保存在设备的缓存或其他东西中......但是:
我不知道这是怎么发生的,因为每次我调用它时下载图像的函数都会重新启动。
这是怎么回事?
如果有人想要我的ImageDownloader 功能(但我百分百确定问题不存在):
private Bitmap downloadBitmap(String url) {
// initilize the default HTTP client object
final DefaultHttpClient client = new DefaultHttpClient();
// forming a HttoGet request
final HttpGet getRequest = new HttpGet(url);
try {
HttpResponse response = client.execute(getRequest);
// check 200 OK for success
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w("ImageDownloader", "Error " + statusCode
+ " while retrieving bitmap from " + url);
return null;
}
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
// getting contents from the stream
inputStream = entity.getContent();
// decoding stream data back into image Bitmap that
// android understands
final Bitmap bitmap = BitmapFactory
.decodeStream(inputStream);
return bitmap;
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
} catch (Exception e) {
// You Could provide a more explicit error message for
// IOException
getRequest.abort();
Log.e("ImageDownloader", "Something went wrong while"
+ " retrieving bitmap from " + url + e.toString());
}
return null;
}
还有我的Edit.php 文件更新数据,包括图像(它有效,经过测试。):
<?php
//1. create connection
$connection=mysql_connect("localhost","lalala","lalala");/
if(!$connection)
{
die("database connection failed:" . mysql_error());
}
$db=mysql_select_db("lalala",$connection);
if(!db)
{
die("database connection failed:" . mysql_error());
}
mysql_query("SET NAMES 'utf8'",$connection);
if ($_POST["lala"]!=null)
{
if ($_POST["lalala"]!=null && $_POST["lalala"]!=null)
{
$sql="UPDATE `lalala`.`lalal` SET `xxx` = '".$_POST[xxx]."', `xxx`='".$_POST[xxx]."', `xxx` = '".$_POST[xxx]."', `xxx`='".$_POST[xxx]."', `xxxt`='".$_POST[xxx]."', `xxx`= '".$_POST[xxx]."', `xxx` = '".$_POST[xxx]."' WHERE `xxx`.`xx` = ".$_POST[xx].";";
$result=mysql_query($sql,$connection);
if(!$result)
{
echo "error.";
//echo "('".mysql_insert_id($connection)."','".$_POST[title]."','".$_POST[snippet]."','".$_POST[cat]."','".$_POST[desc]."','".$_POST[lat]."','".$_POST[lon]."','".$_POST[pub]."','0','0','".$_POST[program]."','".$_POST[addr]."')\n";
die("database connection failed:" . mysql_error());
}
else {
if ($_POST[isnewimg]==1)
{
if (unlink("upload/id".$_POST[id].".jpg"))
{
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name'].$_POST[id].".jpg");
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "1";
}
else {echo "Img update failed".$_POST[id];}
}
else {echo "Img deletion failed".$_POST[id];}
}
else
echo "1"."w/o image. updated ".$_POST[id];
}
}
}
else {
echo "2";
}
mysql_close($connection);
?>
【问题讨论】:
-
警告:您使用的是a deprecated database API,应该使用modern replacement。您也容易受到 SQL injection attacks 的影响,现代 API 可以让您更轻松地从 defend 中获取信息。并且请在输出到 HTML 时使用
htmlspecialchars以防止 XSS。 -
你试过清除数据吗?图片可能被缓存了。
-
@JoeBirch 是的。我通过设备上的
app info清除了数据和缓存。 -
我对php了解不多,但出现这种情况的原因很可能是在服务器上。您的 php 服务器可能正在缓存图像。尝试清除您的服务器缓存。
-
@Tim 我该怎么做?正如我所说,如果我手动转到图像的 url,它会显示新的 ..
标签: php android image bitmap image-uploading