0

I have created a QR code generating website. QR code is generated through PHP QR code generator library by using this code


include_once "../phpqrcode/qrlib.php";
$PNG_TEMP_DIR  = '../qrcodeImages/';
if (isset($_REQUEST['text'])) {
    $content = $_REQUEST['text'];
    $filename = $PNG_TEMP_DIR . 'qr' . md5($content) . '.png';
    QRcode::png($content, $filename, 10);
    echo $image = "<img class='img' src='qrcodeImages/" . basename($filename) . "'/>";
    // $image_src = "qrcodeImage/" . basename($filename);
};

with this ajax call i append the QR code in the required div

$.ajax({
   url: "code/single_input_to_qrcode.php",
   type: "POST",
   data: { text: jquery_plain_text },
   success: (parms) => {
      $("#downloadPart_img img").remove();
      $("#downloadPart_img").append(parms);
   }
});

and under QR code div I have placed a download button which is used to download the QR code for downloading purpose I have used JavaScript library "File Saver" code

        var url = $("#downloadPart_img img").attr('src');
        if (url == "img/white-qr-code.png") {
            $("#error_msg_div").animate({ "top": "20px" });
            error_msg = "Please generate a QR code before download";
            error_msg_div.html(error_msg);
        } else {
            var file_name = url.substring(url.lastIndexOf('/') + 1);
            url = "localhost/qrCodeGenerator/" + url;
            saveAs(url, file_name);
        }

But when user hit download button it show failed to download what kind of issue is that. I thinks this is because when the user hit the download button at the same time the file is saving in the folder so file is not available their at that time. I have search a lot about that but I am fail to get its solution so now I am on this site to find solution so if some one now how to fix this problem so please help me. Advance thanks image of website and failed file at left bottom

enter image description here

Rakesh kumar Oad
  • 1,332
  • 1
  • 15
  • 24
  • Could you provide `url` variable value? – temo Sep 01 '21 at 10:58
  • url is the source of image such as image/pic.png – Umair Mustafa Sep 01 '21 at 15:17
  • You should try [this answer](https://stackoverflow.com/a/14011075/3733151). This way you should be able to download – temo Sep 01 '21 at 15:27
  • no this is not the answer of my question. I think you have some misunderstanding with my question. My problem is that when I create the QR code image with PHP QR code library. And after that when I click it says in download no file. – Umair Mustafa Sep 01 '21 at 18:46
  • its not about downloading issue its about the file when I click the button at that time file is not their or maybe not generated kind of stuff. – Umair Mustafa Sep 01 '21 at 18:47
  • Ok, just in case, could you check if any file can be downloaded without issues? and please provide `url` value, maybe it will help figure this thing out – temo Sep 02 '21 at 12:58

0 Answers0