5iFeR Posted March 6, 2023 Share Posted March 6, 2023 <?php $htmlUrl = "https://faberlic.com/index.php?option=com_flform&idform=514"; // Fetch the HTML code $html = file_get_contents($htmlUrl); if (!$html) { die("Failed to fetch HTML code from $htmlUrl"); } // Extract the image information if (!preg_match('/<img data-type="lang" class="og-image" id="registration-img" style="max-width: 100%;\s*text-align: center; display: none;" src="(.*\.jpg\?v=.*?)" alt="Registration" \/>/', $html, $matches)) { die("Failed to extract image URL from HTML code"); } $imageUrl = $matches[1]; // Fetch the image and save it to a temporary file $tempImage = tempnam(sys_get_temp_dir(), "image"); $imageData = file_get_contents($imageUrl); if (!$imageData) { die("Failed to fetch image data from $imageUrl"); } file_put_contents($tempImage, $imageData); // Display the image if (!is_file($tempImage)) { die("Failed to create temporary image file"); } header("Content-Type: image/jpeg"); readfile($tempImage); // Delete the temporary file unlink($tempImage); ?> may have misdescribed preg_match. i am noob in php. Link to comment https://forums.phpfreaks.com/topic/315978-can-anyone-help-with-importing-an-image/ Share on other sites More sharing options...
requinix Posted March 6, 2023 Share Posted March 6, 2023 Quote Can anyone help with importing an image? Meaning what? Giving us a single sentence of description and dumping a bunch of code doesn't go very far towards persuading us to help with a problem. Including an actual description, like of what you want to do and what you tried and how it seems to be (not) working, does help. Link to comment https://forums.phpfreaks.com/topic/315978-can-anyone-help-with-importing-an-image/#findComment-1606233 Share on other sites More sharing options...
ginerjm Posted March 6, 2023 Share Posted March 6, 2023 I would be very surprised if you can do a file_get_contents on a url. The url suggests that a script has to run and the file_get_contents expects a set of data at the ready, which it will not be. And just what do you mean by "import"? Are you meaning "download"? Link to comment https://forums.phpfreaks.com/topic/315978-can-anyone-help-with-importing-an-image/#findComment-1606237 Share on other sites More sharing options...
kicken Posted March 6, 2023 Share Posted March 6, 2023 6 hours ago, ginerjm said: I would be very surprised if you can do a file_get_contents on a url. You can. It'll make a HTTP request, just like a browser would and give you the response data. Link to comment https://forums.phpfreaks.com/topic/315978-can-anyone-help-with-importing-an-image/#findComment-1606287 Share on other sites More sharing options...
ginerjm Posted March 6, 2023 Share Posted March 6, 2023 My learning for the day... Link to comment https://forums.phpfreaks.com/topic/315978-can-anyone-help-with-importing-an-image/#findComment-1606288 Share on other sites More sharing options...
gizmola Posted March 6, 2023 Share Posted March 6, 2023 Yeah, this seems to be a prefix towards an attempt to mass generate registrations for free gifts from this site. Locking it. Link to comment https://forums.phpfreaks.com/topic/315978-can-anyone-help-with-importing-an-image/#findComment-1606296 Share on other sites More sharing options...
Recommended Posts