Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8807025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:16:22+00:00 2026-06-14T02:16:22+00:00

I have an HTML5 app that saves the canvas image to the server and

  • 0

I have an HTML5 app that saves the canvas image to the server and then provides a link to that image that opens in a new window.

This works fine the first time I save it, but if I create and save a new image and then click on the link it displays the old image that was previously created.

Clicking on refresh will force it to display the new one, but I was wondering if there is a way to make sure it displays the correct image so that I don’t have to refresh the page?

Below is what I am using to save the image.

<script>
function saveImageAs (imgOrURL) {
if (typeof imgOrURL == 'object')
  imgOrURL = imgOrURL.src;
window.win = open (imgOrURL);
setTimeout('win.document.execCommand("SaveAs")', 500);
}
</script>

<script type="text/javascript">

//****************************************************************
// Save canvas content into image file.                         //
//****************************************************************
function saveViaAJAX()
{
document.getElementById('saveimage').style.visibility="hidden";
document.getElementById("debugFilenameConsole").innerHTML="Please wait while your image is been generated";

var testCanvas = document.getElementById('canvas');
var canvasData = testCanvas.toDataURL("image/jpg");
var postData = "canvasData="+canvasData;
var debugConsole= document.getElementById("debugConsole");
debugConsole.value=canvasData;

//alert("canvasData ="+canvasData );
var ajax = new XMLHttpRequest();
ajax.open("POST",'savecanvas.php',true);
ajax.setRequestHeader('Content-Type', 'canvas/upload');
//ajax.setRequestHeader('Content-TypeLength', postData.length);

ajax.onreadystatechange=function()
{
    if (ajax.readyState == 4)
    {
        //alert(ajax.responseText);
        // Write out the filename.
            document.getElementById("debugFilenameConsole").innerHTML="Saved as <a target='_blank' href='myimage.php'> MyImage.jpg"+ajax.responseText+"</a><br>Reload this page to start a new image or click on the link above to open the file.";
    }
}
ajax.send(postData);
    }
    </script>

And the PHP

    <?php
    if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
    {
    // Get the data
    $imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
    // Remove the headers (data:,) part. 
    // A real application should use them according to needs such as to check image type
    $filteredData=substr($imageData, strpos($imageData, ",")+1);
    // Need to decode before saving since the data we received is already base64 encoded
    $unencodedData=base64_decode($filteredData);
    //echo "unencodedData".$unencodedData;
    // Save file.  This example uses a hard coded filename for testing,
    // but a real application can specify filename in POST variable
    $fp = fopen( 'MyImage.jpg', 'wb' );
    fwrite( $fp, $unencodedData);
    fclose( $fp );
    }
    header("Content-Type: image/jpg");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("content-disposition: attachment; filename=MyImage.jpg");
    imagejpeg($img, null, 100);
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:16:24+00:00Added an answer on June 14, 2026 at 2:16 am

    You can try

    var random=new Date();
    var random2=getTime();
    var rand=random+random2;
    
    imgOrURL = imgOrURL.src+'?rnd='+rand
    

    or for PHP

    $rand=rand();
    MyImage.php?rand=<?=$rand?>
    

    or

    $image='MyImage.php?rand='.$rand.'';
    

    For future use, to save headache. Add dates and times first because using md5 , sha1() or a rand() or JavaScript unique key can be a nightmare, example:

    /// This is much cleaner
    
    /11.1.2012/11.05/eachier93.jpg
    /11.1.2012/11.05/4358390485/93.jpg
    /11.1.2012/11.10/3249203489834/234234.jpg
    
    /// then this
    
    /files/342748234234234/234982348394/333535.jpg
    /files/4535345345/234234234234/3332.jpg
    /files/23423434324/023840348234/2343.jpg
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Flash app that I'm looking to port into HTML5. The app
I would like to develop an HTML5 app that I could then package and
I have a Rails app that pulls in music from Soundcloud. This data contains
I have a web app that gathers some data from the user and saves
I have an app that downloads ZIP files from my server, and can download
Making a painting app using HTML5 and Canvas. I think I want to have
I have a Phonegap/Cordova app that runs on iOS. It saves it's data into
I have an HTML (App) file that reads another HTML (data) file via jQuery.ajax()
I have a small helper app that I use to inject scripts into html
http://developer.android.com/tools/publishing/app-signing.html I have a keystore that I already have an alias and password for.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.