By chrisrockwell on
I am using the images module to process images that are uploaded from a different custom content type. When I pass in the $_FILES['files']['tmp_name'] to image_create_node_from() the Images Module stores it as the tmp name with .tmp extension rather than with the appropriate extension for the mime type. I could not find any record of someone having the same issues so I have to assume it's the user and not the module. Rather then do a workaround with re-copying the image after the node is created, I hope I'll be able to get some assistance here.
Using Images.Module v 1.282
Thanks again for taking a look
Comments
_
Looking at the code in image_create_node_from, the filepath is the path and name of the image file on the server.
How come it's being saved as a .tmp file in the first place?
Pete.
The image is being uploaded
The image is being uploaded via a form so I am passing the tmp name as given by php (image_get_info() returns correct metadata on the tmp file). image_create_node_from calls image_copy() but does not change the extension/rename the file. I can do this with only an extra couple lines of code either in my module before image_create_node_from is called, after it is called (lots of renaming would have to happen here) or put the code directly in Images.module but none of the above seems the right way. If the function was not originally intended to handle maybe I can make an attempt at my first contribution :)
Thanks for the reply Pete, if you need more info
_
OK, so what's the form that's uploading the image?
Pete.
The form is a custom node
The form is a custom node type create form that allows the user to add up to three images in one of the fieldsets. The enctype is set at multipart/form-data. Because the form is very long (javascript used to show/hide sections based on responses) I have included below what I think are the relevant pieces as well as the output html. For each image I pass $_FILES['file']['tmp_name'] to image_create_node_from().
A dump of a test submit
Below I have posted a dump of the $_FILES['files'] variable when the form is submitted:
Did you ever figure this
Did you ever figure this out?
Getting the exact same issue in a d7 sandbox module.
Images are saving as .tmp files instead of proper name
Sure
Use the filename in the $destination instead of the directory only when using file_unmanaged_move().
so file_unmanaged_move('inputfile.tmp', 'directory/outputfile.jpg') instead of file_unmanaged_move('inputfile.tmp', 'directory/');
Baris Wanschers (@BarisW)
Drupal specialist