0

Edit: It DOES update, but with a delay of a few hours..

Another Edit;

It happens only on my nexus 4, I tested it today on my SGS1 and it works just as it should. What could be the problem?

You could say its a little complicated so read carefully:

I have an app that uploads an image to the net, (the image can be anything, from user's device).

I have now added an edit function to that structure, where the user can also upload a new image if he would like to change the old one.

It DOES work.. I tested it through my browser, and the image on the server DOES change.

but on the other hand, on the app, for some reason it does not (the image doesnt change, even though the image on the server has now changed and the previous image doesnt exist anymore.).

Its like, it is saved in the device's cache or something.. BUT:

I have no idea how this is happening because the function that downloads the image stars all over again every time I call it.

How come this is happening?

if anyone wants my ImageDownloader function (but Im hundred precent sure the problem is not there):

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;
        }

And my Edit.php file that updates the data, including the image (it works, tested.):

<?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);
?> 
mn6vdv23g
  • 734
  • 2
  • 10
  • 33
  • 1
    **Warning:** you're using [a **deprecated** database API](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) yourself from. And please use [`htmlspecialchars`](http://php.net/htmlspecialchars) when outputting to HTML to prevent XSS. – Marcel Korpel Dec 06 '13 at 23:45
  • Have you tried clearing data? The image may be cached. – Joe Birch Dec 06 '13 at 23:48
  • @JoeBirch yes. I cleared the data and cache through `app info` on the device. – mn6vdv23g Dec 06 '13 at 23:51
  • I don't know much about php but the reason behind this situation is probably on the server. Your php server might be caching the image. Try to clear your server cache. – Timuçin Dec 07 '13 at 00:06
  • @Tim how can I do that? And as I said, if I manually go to the url of the image, it shows the new one.. – mn6vdv23g Dec 07 '13 at 01:07
  • could you try clearing the mysql cache? http://stackoverflow.com/questions/5231678/clear-mysql-query-cache-without-restarting-server – Timuçin Dec 07 '13 at 12:49

1 Answers1

2

If the server is caching the image, try to reset it to confirm that is the real problem.

In the client side:

If you are loading the image from a URL, for example:

http://ejemplo.com/imagen.png

You can generate an id for each request and add it in the URL like this:

http://ejemplo.com/imagen.png?request_id=5385683

I do not know in what platform you are working, but this works in browsers.

José María
  • 790
  • 13
  • 24
  • how could this help? I mean, on the browser, I see the new image, but the app still shows the old one.. – mn6vdv23g Dec 07 '13 at 10:55
  • Oh, and how can I reset my server? its a free hosting server that I found on the net... also how can I generate an id for each request? – mn6vdv23g Dec 07 '13 at 10:59
  • I mean, restart the server, sorry. But if it's a free hosting, I doubt you can do it. – José María Dec 12 '13 at 17:19
  • In the case of the image, only suggested you try to add a query in the url for each new request. Thus, the application will probably take it as a new url, this works in browsers. – José María Dec 12 '13 at 17:29
  • Finally, Why do not you just change the file name in each update? – José María Dec 12 '13 at 17:30