PHP set an image on my server as uploaded temp file - php

I am editing a photo gallery script to allow the use of TIFF to be uploaded and saved, but i must keep the files in jpg format also for web viewing.
What I have done is installed image magick to convert TIF to JPEG, once i have it converted I want the script to continue with making thumbnails, zoom images, etc. it makes them from
$_FILES['image']['tmp_name']
Is there a way to set my newly created file as $_FILES['image']['tmp_name']? my new jpeg file path is set to $nw.
basically I need
$nw='path/to/newfile.jpg';
$_FILES['image']['tmp_name']=$nw;
but it does not work. any ideas?

If you need to work on the same file across multiple page requests, move it somewhere safe using move_uploaded_file.
If the functions that you wrote require access to $_FILES['image']['tmp_name'], rewrite them to accept the name of the file as a parameter and call them using the new location of the file as argument.

Related

how to execute jpg or other extensions like php

I want to execute only one or two jpg files like php in a folder.
forexample
www/folder/index.jpg should run and shown like www/folder/index.php
or
www/folder/index.php should run and shown like www/folder/index.jpg but it should work as php and it should shown as jpg
and other jpg files should run it is own name
www/folder/photo.jpg > www/folder/photo.jpg
You can't execute JPEG files per se, but you can have them be a PHP script that generates JPEG data to use in e.g. a <img> tag.
You need to set the handler for the file to application/x-httpd-php, output a content type of image/jpeg in the script, and, most importantly, output JPEG data. Might want to consider naming it <something>.jpg.php so you don't have to do the first one though, since that's server configuration.

Display animated GIF from outside public directory (GD?)

Once users upload their images to a non public (i.e outside htdocs or public_html folder) folder, I use GD to fetch the image from that folder. This is all in the name of security, as the images themselves are never displayed without being processed.
The issue lies in animated GIFs, which GD is only capable of displaying by showing only it's first frame.
I know that there are classes out there that can slice the gifs up into their respective frames and "glue" them back together, but I'm looking to display these on the fly...
I don't want to create a new animated gif and show that, but rather have a GD script that renders the image from the information it gets from the photo directory, located outside of the public folder.
Thanks so much!
If you're not manipulating the image at all, I would just return the contents of the file with the correct header.
For example:
<?php
$file = 'whatever.gif';
// Do whatever checks you want on permissions etc
header('Content-type: image/gif');
readfile($file);
?>
Readfile outputs the contents of the file, and the header makes sure the browser sees it as a gif and shows it. Because you're not using GD it will still be animated.
The catch with this method is you'll need to know the content type for each file to server it correctly.
http://php.net/manual/en/function.readfile.php

How to recieve & store an image file from another server, being passed programatically with paramaters?

I am using the API of an image editing website (pixlr.com) for use by members of my site. I open Pixlr.com in an iframe where they can create an image and upon SAVE, pixlr sends the image file by use of parameters.
I want to save these image files (unique for each member) in a folder on my server (or on Amazon's S3 image server), using PHP. How do I receive their parameters ("image") of the image file and store them on my/Amazon's image server?
If the image is sent to your PHP script via POST, then you should be able to do something like this:
$handle = fopen($imageName, "wb");
fwrite($handle, $_POST["image"]);
fclose($handle);
Where $imageName is the absolute path and filename of the image where you want to save it (make sure you Apache user has write permissions to that directory). Depending on the picture's encoding you may need to figure out which extension to save it with (ie .jpg, .bmp, .png, etc).
EDIT:
Looks like they are sending the image via $_FILES. Try this:
move_uploaded_file($_FILES["image"]["tmp_name"], "/home/path/domain.com/upload/". time() .".png");

Saving different image types with php and just renaming the target file path?

How much difference does it make if I want to save all uploaded images to my site as gif if I just do...
$target = 'images/avatars/' . md5($user['id']) . '.gif';
Rather than creating a gif in php copying the temp image and then saving? Will the browser still load the file? Will it still recognise the old file type? Does it really matter from a point of view where these images will never be downloaded purposelly through my site?
Thanks
Yes, you can rename images to .gif and browsers will still display them as jpg even if you load them with a .gif extension.
It will still have a jpg filetype, just with a .gif extension. (Just tested this)

Downloading images from a server iPhone SDK

I have created a program which allows me to upload images to my server. They are given a random file name when uploaded. I want to be able to download all the images from a folder on the server so I can display them in my application. The only example I have seen requires that I know the file name of the images which I don't. How could I download all the images in a given directory (and store the downloads in an NSArray)? If there is no native way to do it does anyone know a way that it could be done via calling a PHP script? (I use a PHP script which the iPhone calls to upload the images).
Thanks.
To list all images in a directory using PHP and return a JSON encoded string:
$path = '/full/path/to/images/';
// find all files with extension jpg, jpeg, png
// note: will not descend into sub directorates
$files = glob("{$path}/{*.jpg,*.jpeg,*.png}", GLOB_BRACE);
// output to json
echo json_encode($files);
you can call a php script that will return the url for all of your images.
something like
yoursite.com/image123.jpg;yoursite.com/image213.jpg;yoursite.com/imageabc.jpg
then you parse the result, split by ";" and get the array of urls which you need to download.

Categories