Home  >  Q&A  >  body text

Download - php What is the process of saving images to the local mobile phone?

Add watermark to the picture on the mobile phone and then save it locally on the phone
Why are the downloads you see now all downloaded to the server? Can't they be downloaded to the local phone?
The download code refers to this

    public function downloadImage($url, $path='images/')
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        $file = curl_exec($ch);
        curl_close($ch);
        $this->saveAsImage($url, $file, $path);
    }

    private function saveAsImage($url, $file, $path)
    {
        $filename = pathinfo($url, PATHINFO_BASENAME);
        $resource = fopen($path . $filename, 'a');
        fwrite($resource, $file);
        fclose($resource);
    }
天蓬老师天蓬老师2650 days ago857

reply all(4)I'll reply

  • 習慣沉默

    習慣沉默2017-06-23 09:13:42

    DownloadImg downloads remote images to the local server. If you need to save the image locally on your mobile phone, this can only be achieved by browser and js. PHP runs on the server side

    reply
    0
  • 三叔

    三叔2017-06-23 09:13:42

    The correct answer upstairs is that downloading can be done without using the JS a tag

    reply
    0
  • 为情所困

    为情所困2017-06-23 09:13:42

    Just link the file address directly in your browser

    reply
    0
  • 学习ing

    学习ing2017-06-23 09:13:42

    In response to your question, the answer is: No.

    This code of yours saves remote files to the server where PHP is located through http.

    To download to your mobile phone, refer to http file download.

    header('Content-Disposition: attachment; filename=xxxxx');
    readfile('File on PHP server');

    reply
    0
  • Cancelreply