Jump to content

Can anyone help with importing an image?


5iFeR

Recommended Posts


 

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.