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

pbarnett’s picture

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.

chrisrockwell’s picture

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

pbarnett’s picture

OK, so what's the form that's uploading the image?

Pete.

chrisrockwell’s picture

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().

$form['images'] = array(
    '#type' => 'fieldset',
	'#title' => t('Upload any images'),
	'#description' => t('Up to 3 images are allowed'),
  );
  $form['images']['image_upload1'] = array(
    '#type' => 'file',
	'#title' => t('Image upload'),
  );
  $form['images']['image_upload2'] = array(
    '#type' => 'file',
	'#title' => t('Image upload'),
  );
  $form['images']['image_upload3'] = array(
    '#type' => 'file',
	'#title' => t('Image upload'),
  );
<fieldset><legend>Upload any images</legend><div class="description">Up to 3 images are allowed</div><div class="form-item" id="edit-image-upload1-1-wrapper">
 <label for="edit-image-upload1-1">Image upload: </label>
 <input name="files[image_upload1]" class="form-file" id="edit-image-upload1-1" size="60" type="file">

</div>
<div class="form-item" id="edit-image-upload2-1-wrapper">
 <label for="edit-image-upload2-1">Image upload: </label>
 <input name="files[image_upload2]" class="form-file" id="edit-image-upload2-1" size="60" type="file">

</div>
<div class="form-item" id="edit-image-upload3-1-wrapper">
 <label for="edit-image-upload3-1">Image upload: </label>
 <input name="files[image_upload3]" class="form-file" id="edit-image-upload3-1" size="60" type="file">

</div>
</fieldset>
chrisrockwell’s picture

Below I have posted a dump of the $_FILES['files'] variable when the form is submitted:

Array
(
    [name] => Array
        (
            [image_upload1] => Ed-Working.jpg
            [image_upload2] => Ed-Suit.jpg
            [image_upload3] => 
        )

    [type] => Array
        (
            [image_upload1] => image/jpeg
            [image_upload2] => image/jpeg
            [image_upload3] => 
        )

    [tmp_name] => Array
        (
            [image_upload1] => c:/wamp/tmp\php19A.tmp
            [image_upload2] => c:/wamp/tmp\php19B.tmp
            [image_upload3] => 
        )

    [error] => Array
        (
            [image_upload1] => 0
            [image_upload2] => 0
            [image_upload3] => 4
        )

    [size] => Array
        (
            [image_upload1] => 42575
            [image_upload2] => 17708
            [image_upload3] => 0
        )

)

Macronomicus’s picture

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

BarisW’s picture

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