Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You want to reload the IMG source upon change. So what you need to do is to replace the <code>SRC=</code> value of the IMG tag, by adding a dummy query to avoid caching:</p> <pre><code>jQuery('#save_image').click(function(){ var image_name = jQuery('#hidden_image_name').val(); jQuery.ajax({ url:'text_image.php', data:'file='+image_name, type:'get', success:function(data){ jQuery('#image').attr('src', jQuery('#image') .attr('src')+'?'+Math.random()); } }); }); </code></pre> <p>The PHP script needs output nothing, just rewrite the image file</p> <pre><code>&lt;?php $file = 'upload_pic/'.$_GET['file']; $im = writeToImage($file, 'PHPRO rules again'); imageJPEG($im, $file, 95); // 95% quality die(); ... ?&gt; </code></pre> <p>You may want to output a JSON stating 'success' or 'failure', though, just in case.</p> <p>You also want to check that <code>$_GET['file']</code> is a valid, accessible, allowed, image. For example you might force the file to be a basename:</p> <pre><code> $file = 'upload_pic/'.basename($_GET['file']); if (!file_exists($file)) // ...no such file... if (false === getImageSize($file)) // ...doesn't look like an image... // etc. </code></pre> <h1>Another way</h1> <p>If you want to keep both original and 'captioned' image, you need to <a href="https://stackoverflow.com/questions/9648882/generating-unique-filename">create a new file</a>, and therefore output the new name so that jQuery can replace the SRC attribute.</p> <p>For example:</p> <pre><code> $new = 'upload_pic/'.uniqid().'.jpg'; ...create the file and put $im into it, as above... Header('Content-Type: application/json;charset=utf8'); die(json_serialize(array("src" =&gt; $new))); // Or if you don't want json_serialize (BUT THEN $new may only contain printable ASCII-7 characters that need no escaping. "[a-z][0-9]-_." if you want to be sure). die("{\"src\":\"{$new}\"}"); </code></pre> <p>in jQuery, <code>data</code> will now contain <code>$new</code>, so:</p> <pre><code> success:function(data){ jQuery('#image').attr('src', data.src); } </code></pre> <p>(in the page, you may need to update other fields if you want to re-caption an already-captioned image).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload