# Images not writing with my routines

**URL:** https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122
**Category:** Hosting Support
**Created:** [December 2, 2022, 9:41am UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122 "2022-12-02T09:41:13Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 2, 2022, 9:41am UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/1 "2022-12-02T09:41:13Z")

</div>

### Username (e.g. epiz\_XXX) or Website URL

epiz\_33087480  
(please specify the website or account you are asking about)  
[http://www.deniserose.epizy.com/images/nowplaying\_artwork\_2.png](http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png)

### Error Message

No message the image just doesnt update  
(please share the FULL error message you see)

### Other Information

I am trying to update it as follows but for some reason this is failing in add\_trak.php

code snipit

```auto
$artwork = isset($_REQUEST['artwork']) && ($_REQUEST['artwork'] !== '') ? $_REQUEST['artwork'] : false;
if ($artwork !== false) {
    $artwork = base64_decode($artwork);
    $r = fopen('images/nowplaying_artwork_2.png', 'wb');
    if ($r !== false) {
        fwrite($r, $artwork);
        fclose($r);
    } else {
        ReturnError(500, 'Failed to write artwork to a file');
    }
}

```

(other information and details relevant to your question)  
Any ideas please as this is strange and I guess I am missing something

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 2, 2022, 11:26am UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/2 "2022-12-02T11:26:58Z")

</div>

I have checked chmod and file is -rw-rw-rw so am not sure why its not writing image as it was before. Is my reference wrong do I need something like /htddocs/images/ nowplaying\_artwork\_2.png?

---

<div class="post-metadata">

### Author: ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)
#### Post date: [December 2, 2022, 8:15pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/3 "2022-12-02T20:15:26Z")

</div>

Could you please double check the file that’s actually being stored?

Our hosting sends quite aggressive caching headers by default, so it’s possible that your image may have been updated in the background, but your browser just isn’t loading it.

If this is the case, you can bypass the cache by adding a query parameter to the URL (like `nowplaying_artwork_2.png?version=latest`), which bypasses the cache.

---

<div class="post-metadata">

### Author: ![Oxy](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/oxy/32/37989_2.png) [@Oxy](https://forum.infinityfree.com/u/Oxy)
#### Post date: [December 2, 2022, 8:30pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/4 "2022-12-02T20:30:09Z")

</div>

@anon14276620 what do you really want to achieve?  
Do you want it to automatically change the “album cover” from the play list as soon as a new song/set starts playing?

I peeked a bit into your previous code

- [now\_playing.php with SQL support | DJSoft.Net Community Forums](https://www.djsoft.net/community/threads/now_playing-php-with-sql-support.7281/post-36067)

* * *

By the way, copy the generated code (view source) from your page and paste it [on the validator](https://validator.w3.org/#validate_by_input).  
You have over 500 errors

some are more important, for example:

currently all your URLs end with a quotation mark at the end (because you didn’t put a quotation mark at the beginning

 ![Screenshot 2022-12-02 125855](https://forum-cdn.infinityfree.net/original/3X/0/9/09f7141d513a185feebc1a958d24c1a574b70932.png)

 ![Screenshot 2022-12-02 123630](https://forum-cdn.infinityfree.net/original/3X/5/1/519587d5a4b57eda6cb17b212c90b5b49cb94f2d.png)

* * *

PHP - you need to prepare this PHP code for the newer version that will come soon

 ![Screenshot 2022-12-02 123546](https://forum-cdn.infinityfree.net/original/3X/b/6/b6a25294ba18211648ec13c23df89cc4bcf59762.png)

---

<div class="post-metadata">

### Author: ![Admin](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/admin/32/36437_2.png) [@Admin](https://forum.infinityfree.com/u/Admin)
#### Post date: [December 3, 2022, 11:45am UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/5 "2022-12-03T11:45:28Z")

</div>

Note that there are some posts about this in the other topic, roughly from this post down:

> [@All web pages return http 500 not sure why](https://forum.infinityfree.com/t/all-web-pages-return-http-500-not-sure-why/68945/33):
>
> Thanks but I think the problem is the page references have changed from my previous system i was on i was using var base64file2 = $("img#np\_track\_artwork").attr("src", "data:image/png;base64,"+data); To get the image base64 for the iage but dont think this working

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 2:19pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/6 "2022-12-03T14:19:59Z")

</div>

Ok here goes Oxy . I hope this helps and than you for your help its much appreciated I will try my best:  
1 ) page does not refresh with latest image in [http://www.deniserose.epizy.com/images/nowplaying\_artwork\_2.png](http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png). I even deleted this image and refreshed page (see my posts for images the same error) was displayed nothing saying image not found. instead if you refresh this it appears with some major delay.

1. the image write in file ‘add\_track.php’ creates records and image . It does not seem to do this either properly as records are missing from SQL and file does not get changed all the time. I have placed a ftp upload from my end every time track changes of it so that other testing can take place… If I open refresh of [http://www.deniserose.epizy.com/music\_now\_playing.php](http://www.deniserose.epizy.com/music_now_playing.php) the icon does not change if I open the image [http://www.deniserose.epizy.com/images/nowplaying\_artwork\_2.png](http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png) if I refresh this it does show correct image again some strange delay.
2. .My pages to refresh this [http://www.deniserose.epizy.com/music\_now\_playing.php](http://www.deniserose.epizy.com/music_now_playing.php) is in Javascript file ‘fetch\_updater .js’ uses Ajax Timer an calls its page routinely to check image change but neither process in it seem to deliver base64from image on screen and in file which has worked without syntax error elsewhere. the chrome f12 debugger finds no errors when you run a trace and record network it shows fetchupdater.js firing and does not provide 64code in .base64file1 or base64file2  
code snipit from fetchupdater.js:

```auto
 const toDataURL = url => fetch(url)
  .then(response => response.blob())
  .then(blob => new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onloadend = () => resolve(reader.result)
    reader.onerror = reject
    reader.readAsDataURL(blob)
  }))

     var image = document.createElement("img");
    image.src = 'http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png';

    var base64file1;
   
    toDataURL("/images/nowplaying_artwork_2.png", function(data) {
        then(dataUrl => console.log('RESULT:', dataUrl));
        base64file1 = dataUrl;
        });
    
    //image.remove();
    
    var base64file2 = $("img#np_track_artwork").attr("src", "data:image/png;base64,"+data);

```

 ![](https://forum-cdn.infinityfree.net/original/3X/e/2/e2ca57ac7ae08cf65313c56d13f85d3ed8ab4756.png)

1. my php all use things like strlen( and fwrite( from PHP which don’t seem to function either.  
[https://i.gyazo.com/549031e220324ba71f6e165e6822afdd.png](https://i.gyazo.com/549031e220324ba71f6e165e6822afdd.png) as you can see blank records are created and some records shown on the page do not remain in sql

I am aware not all files have been converted to use your different sql that you use .

On a note on the errors you recorded these seem to be all stylistic errors which do not affect function. Also please note i don’t have my last working code previous website wont provide it to me . So this is causing repeat debugging .

I had pondered if this indicated corruption on the site on the server ?

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 5:34pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/7 "2022-12-03T17:34:34Z")

</div>

Would you be so kind to get open a command prompt if this server is running windows and run SFC / SCANNOW or on linux/unix use Fsck

---

<div class="post-metadata">

### Author: ![EdwinTigor](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/edwintigor/32/28150_2.png) [@EdwinTigor](https://forum.infinityfree.com/u/EdwinTigor)
#### Post date: [December 3, 2022, 5:41pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/8 "2022-12-03T17:41:27Z")

</div>

Though it is running.  
Escape cache read external img url by adding random url get modifier  
… owplaying\_artwork\_2.png?s=0556332222333

use math random or generated string.

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 6:16pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/9 "2022-12-03T18:16:43Z")

</div>

my urls are added with “\<img id=#np\_track\_artwork src=/images/nowplaying\_artwork\_2.png?t=”+$time+" alt=‘Playing track artwork’ width=200 height=200\>" but i tried  
“\<img id=#np\_track\_artwork src=/images/nowplaying\_artwork\_2.png?version=”+$time+" alt=‘Playing track artwork’ width=200 height=200\>"

It was still no better . I asked for sfc as my fetch routine was working and was then today producing corrupted table . I had to go back to a copy here and start again hopeful it held

---

<div class="post-metadata">

### Author: ![EdwinTigor](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/edwintigor/32/28150_2.png) [@EdwinTigor](https://forum.infinityfree.com/u/EdwinTigor)
#### Post date: [December 3, 2022, 6:42pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/10 "2022-12-03T18:42:05Z")

</div>

no. Copy my file for learn purpose.  
Over here:

```auto
toDataURL('http://viena.lovestoblog.com/imgEdit/img/nowplaying_artwork_2.png')
  .then(dataUrl => {
    console.log('RESULT:', dataUrl)
    document.getElementById("export").value = dataUrl;
  })

```

change to

```auto
toDataURL('http://viena.lovestoblog.com/imgEdit/img/nowplaying_artwork_2.png?t=077.765')
  .then(dataUrl => {
    console.log('RESULT:', dataUrl)
    document.getElementById("export").value = dataUrl;
  })

```

**Don’t ruin your original html tag**. Its on script to change  
On your hosting it gonna be

```auto
toDataURL('http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png?t=078885')
  .then(dataUrl => {
    console.log('RESULT:', dataUrl)
    document.getElementById("export").value = dataUrl;
  })

```

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 4:03pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/11 "2022-12-03T16:03:30Z")

</div>

### Username (e.g. epiz\_XXX) or Website URL

epiz\_33087480  
(please specify the website or account you are asking about)  
[http://www.deniserose.epizy.com/music\_now\_playing.php](http://www.deniserose.epizy.com/music_now_playing.php)

### Error Message

none  
(please share the FULL error message you see)  
Is it possible to store images as blob in sql record of approx. 200x200px

### Other Information

I am just wondering  
(other information and details relevant to your question)  
Any suggestions please ?

---

<div class="post-metadata">

### Author: ![ShazamBolt8](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/shazambolt8/32/29637_2.png) [@ShazamBolt8](https://forum.infinityfree.com/u/ShazamBolt8)
#### Post date: [December 3, 2022, 5:40pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/12 "2022-12-03T17:40:26Z")

</div>

Storing blob is a very poor practice. However what you do is, upload the image on the server and store its path in the database.  
Like `home/vol/assets/user/sc-12/koala.png`.

---

<div class="post-metadata">

### Author: ![EdwinTigor](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/edwintigor/32/28150_2.png) [@EdwinTigor](https://forum.infinityfree.com/u/EdwinTigor)
#### Post date: [December 3, 2022, 5:46pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/13 "2022-12-03T17:46:28Z")

</div>

Yes, for 200x200 px mediumblob type is enough.

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 6:07pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/14 "2022-12-03T18:07:53Z")

</div>

I don’t really understand them in SQL I am hopeful for help in SQL they come up as [BLOB-1B] in PHPBrowser as empty if i have a field ImagBase64 defined as BLOB .Can I load this with base64 as in base64\_decode($artwork2); or do I have to add it to a blob with url then upload that in sql or is there a better way of compacting it. I thought it could be resized in a image by creating new image resized I haven’t worked that out yet?  
Here is what I have to convert it :

```auto
var image = document.createElement("img");
image.src = 'http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png?tr=w-200,h-200'
$b64Data= base64_decode($artwork);
const byteCharacters = atob(b64Data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
    byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], {type: contentType});

```

Is this the best way to do this ?

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 6:08pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/15 "2022-12-03T18:08:59Z")

</div>

> [@ShazamBolt8](#):
>
> Storing blob is a very poor practice. However what you do is, upload the image on the server and store its path in the database.  
> Like `home/vol/assets/user/sc-12/koala.png`.

I think this would take forever to load a list of them but thanks

---

<div class="post-metadata">

### Author: ![EdwinTigor](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/edwintigor/32/28150_2.png) [@EdwinTigor](https://forum.infinityfree.com/u/EdwinTigor)
#### Post date: [December 3, 2022, 6:26pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/16 "2022-12-03T18:26:44Z")

</div>

Dont have generated method use counter

My generated  
var startDate = new Date(‘1/1/2019’); // this  
var startMsec = startDate.getTime();// we get the time from the date in milliseconds  
var toDate = new Date(); // the current date.  
var ourTime = toDate.getTime();// we grap  
var elapsed = (ourTime - startMsec) / 1000;

url=“xxxxx.jpg?t=”+elapsed;

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 6:31pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/17 "2022-12-03T18:31:08Z")

</div>

> [@anon14276620](#):
>
> ```auto
> var image = document.createElement("img");
> image.src = 'http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png?tr=w-200,h-200'
> $b64Data= base64_decode($artwork);
> const byteCharacters = atob(b64Data);
> const byteNumbers = new Array(byteCharacters.length);
> for (let i = 0; i < byteCharacters.length; i++) {
> byteNumbers[i] = byteCharacters.charCodeAt(i);
> }
> const byteArray = new Uint8Array(byteNumbers);
> const blob = new Blob([byteArray], {type: contentType});
> 
> ```

The question is how do i get it back fast to base64 and image from sql?

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 6:37pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/18 "2022-12-03T18:37:03Z")

</div>

> [@EdwinTigor](#):
>
> My generated  
> var startDate = new Date(‘1/1/2019’); // this  
> var startMsec = startDate.getTime();// we get the time from the date in milliseconds  
> var toDate = new Date(); // the current date.  
> var ourTime = toDate.getTime();// we grap  
> var elapsed = (ourTime - startMsec) / 1000;
> 
> url=“xxxxx.jpg?t=”+elapsed;

Thank you Ewin but my fetch is not loading so it will not do this the base64 still is not coming back in my routine in js idk why

Hugs

---

<div class="post-metadata">

### Author: ![EdwinTigor](https://forum.infinityfree.com/user_avatar/forum.infinityfree.com/edwintigor/32/28150_2.png) [@EdwinTigor](https://forum.infinityfree.com/u/EdwinTigor)
#### Post date: [December 3, 2022, 6:39pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/19 "2022-12-03T18:39:26Z")

</div>

```auto
<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=9" />
   <meta name="viewport" content="width=device-width, initial-scale=1">
   	
   <script type="text/javascript" src="src/js/jquery-3.4.1.min.js"></script>
</head>
<body>
	<img id="img_artwork" width="220" height="277"
src="http://viena.lovestoblog.com/imgEdit/img/edwin.jpg" alt="Lesson">
	<script>
  
  function process() {
	alert("start");
    //var image = document.createElement("img");
    //image.src = 'http://viena.lovestoblog.com/imgEdit/img/nowplaying_artwork_2.png';
    //var base64file1;
    //image.remove();
   
   data=document.getElementById("export").value;
   alert(data);
    var base64file2 = data;
    $("#img_artwork").attr("src", base64file2);
    
    alert("ok");
}
</script>

<h1>HTML DOM Events</h1>
<h2>The onclick Event</h2>

<p>The onclick event triggers a function when an element is clicked on.</p>
<p>Click to trigger a function that will output "Hello World":</p>

<button onclick="myFunction()">Click me</button>
<button onclick="p1()">img Click me</button><br>

<button onclick="process()">Process</button>
<input onkeypress="process()" type="text" id="export" name="export">

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}

function p1() {
	alert("00");
  const toDataURL = url => fetch(url)
  .then(response => response.blob())
  .then(blob => new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onloadend = () => resolve(reader.result)
    reader.onerror = reject
    reader.readAsDataURL(blob)
  }))
  alert("11");

toDataURL('http://viena.lovestoblog.com/imgEdit/img/nowplaying_artwork_2.png')
  .then(dataUrl => {
    console.log('RESULT:', dataUrl)
    document.getElementById("export").value = dataUrl;
  })
  
  alert("ok");
}

function px() {
	alert("00");
  const toDataURL = url => fetch(url)
  .then(response => response.blob())
  .then(blob => new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onloadend = () => resolve(reader.result)
    reader.onerror = reject
    reader.readAsDataURL(blob)
  }))

  alert("ok");
}

</script>

</body>
</html>

```

It works. I need time to modify better. Ready to use to get base64.  
[http://viena.lovestoblog.com/imgEdit/r3.php](http://viena.lovestoblog.com/imgEdit/r3.php)

---

<div class="post-metadata">

### Author: ![anon14276620](https://forum.infinityfree.com/letter_avatar/anon14276620/32/5_5575768a8748004e209b776fc1b2916d.png) [@anon14276620](https://forum.infinityfree.com/u/anon14276620)
#### Post date: [December 3, 2022, 6:49pm UTC](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122/20 "2022-12-03T18:49:10Z")

</div>

> [@anon14276620](#):
>
> Here is what I have to convert it :
> 
> ```auto
> var image = document.createElement("img");
> image.src = 'http://www.deniserose.epizy.com/images/nowplaying_artwork_2.png?tr=w-200,h-200'
> $b64Data= base64_decode($artwork);
> const byteCharacters = atob(b64Data);
> const byteNumbers = new Array(byteCharacters.length);
> for (let i = 0; i < byteCharacters.length; i++) {
> byteNumbers[i] = byteCharacters.charCodeAt(i);
> }
> const byteArray = new Uint8Array(byteNumbers);
> const blob = new Blob([byteArray], {type: contentType});
> 
> ```

Didn’t work created empty field so why does this not work either as it looked ok ?

Hugs

[Next page](https://forum.infinityfree.com/t/images-not-writing-with-my-routines/69122.md?page=2)
