How to generate a picture of graph of the results of voting and how to save the image in my server host, to continue to use it. How can I do this?
Generating Grapsh etc.
You can use link PHPExcel
and there is a possibility to save all generated files
eg: $objWriter->save('namee.xls'); check detail from the documentation
Saving without using PHPexcel etc.
if you have a graph or smth else and you want to save it on your server side
to save something you can use
$fp = fopen($name, "w");
fwrite($fp, $content); // this line saves
fclose($fp);
Related
I'm trying to figure out how to pull an image from a third party website that gets changed every so often. Basically I am using Vbulletin software and would like to avoid a mixed content warning - hosting an image (HTTP) from another site onto mine (HTTPS). I would like the function basically to call the image in php, save the image to a folder on my server and then a php function to call the saved image on my server and display it. Thoughts? Thanks. I keep getting a failure to open stream on file_get_contents...
ob_start();
//Get the file
$content = file_get_contents("http://www.defconwarningsystem.com/current/defcon.jpg");
//Store in the filesystem.
$fp = fopen("/images/defcon/defcon.jpg", "w");
fwrite($fp, $content);
fclose($fp);
$html = ob_get_clean();
return $html;
Change
$content = file_get_contents("http://www.defconwarningsystem.com/current/defcon.jpg");
To
$content = file_get_contents("//defconwarningsystem.com/current/defcon.jpg");
And see if that works.
If file_get_contents doesn't work try cURL.
See example usage on php reference
I'm using AWS PHP sdk to save images on S3. Files are saved privately. Then, I'm showing the image thumbnails using the S3 file url in my web application but since the files are private so the images are displayed as corrupt.
When the user clicks on the name of file, a modal is opened to show the file in larger size but file is displayed as corrupt there as well due to the same issue.
Now, I know that there are two ways to make this working. 1. Make the files public. 2. Generate pre-signed urls for files. But I cannot go with any of these two options due to the requirements of my project.
My question is that is there any third way to resolve this issue?
I'd highly advise against this, but you could create a script on your own server that pulls the image via the API, caches it and serves. You can then restrict access however you like without making the images public.
Example pass through script:
$headers = get_headers($realpath); // Real path being where ever the file really is
foreach($headers as $header) {
header($header);
}
$filename = $version->getFilename();
// These lines if it's a download you want to do
// header('Content-Description: File Transfer');
// header("Content-Disposition: attachment; filename={$filename}");
$file = fopen($realpath, 'r');
fpassthru($file);
fclose($file);
exit;
This will barely "touch the sides" and shouldn't delay the appearance of your files too much, but t's still going to take some resources and bandwidth.
You will need to access the files through a script on your server. That script will do some kind of authentication to make sure the request is valid and you want them to see the file. Then fetch the file from S3 using a valid IAM profile that can access the private files. Output the file
Instead of requesting the file from S3 request it from
http://www.yourdomain.com/fetchimages.php?key=8498439834
Then here is some pseudocode in fetchimages.php
<?php
//if authorized to get this image
$key=$_GET['key'];
//validate key is the proper format
//get s3 url from a database based on the $key
//connect to s3 securely and read the file from s3
//output the file
?>
as far as i know you could try to make your S3 bucket a "web server" like this but then you would probably "Make the files public".Then if you have some kind of logic to restrict the access you could create a bucket policy
I am using url2png to get screenshots from pages. However, instead of asking the image every time, I want to save it onto an external server via FTP.
My first approach was to use:
$image = fopen($src,"r");
And then an ftp_fput. But as url2png may take about 5 secs to get the screenshot, the ftp_fput uploads an empty file.
Do I need to save the file locally first? or is there a workaround?
Thanks!
Found a solution using this question: Using file_get_contents and ftp_put
$fp = fopen('php://temp', 'r+');
fputs($fp, file_get_contents($src));
rewind($fp);
There is a file located on a server. Lets call it "Movie".
My site's users need to downoad this movie, but the movie can only be downloaded by my website's IP.
Is there a way to download Movie to my server and from there to the user?
I can do that by "put_content" but I need the client to download the file WHILE my server downloads it.
Thanks!
You can make use of the standard wrappers PHP offersÂDocs and combine that with stream_copy_to_streamÂDocs:
Example / Demo:
<?php
$url = 'http://example.com/some.url';
$src = fopen($url, 'r');
$dest = fopen('php://output', 'w');
$bytesCopied = stream_copy_to_stream($src, $dest);
Related (couldn't find a better duplicate so far):
Remotely download a file from an external link to my server - download stops prematurely
Take a look at the readfile function.
http://php.net/manual/en/function.readfile.php
I am facing the task of having to upload a snapshot to the server. But I don't want the user to download the image to their computer.
I have explored a few solutions of generating an image serverside with PHP, but they all seem to use a method where the server sends the image to the user.
See for instance: http://mattkenefick.com/blog/2008/11/06/saving-jpegs-with-flash/
I'm wondering if it's possible to save $GLOBALS["HTTP_RAW_POST_DATA"], which in that example contains the ByteArray sent by Flash, to the server as an image file....
Use php code that is along these lines to save the contents of $GLOBALS["HTTP_RAW_POST_DATA"]
// untested code
$imageBytes = $GLOBALS["HTTP_RAW_POST_DATA"]
// in real code you better create a new file for every upload :-)
$file = fopen("uploads/test.jpg", "w");
if(!fwrite($file, $imageBytes)){
return "Error writing to file: $file";
}
fclose($file);