Great module. Got everything working.

But even after playing around for a week, I could not get the image to display in preview when the cck content is created.

It displays an empty box for the image but no image.

I found that "src" attribute for preview image is set to the image directory under . However no image has been uploaded to this directory. Image is uploaded only when i save the content.

I also found that a file corresponding to the image is created in temp directory.

I am not sure of the mechanism of how, when and where the image is supposed to be uploaded. But from the path generated for the preview image, it does seem that image should have been uploaded to files/image directory when we press upload button.

Any help will be appreciated.

CommentFileSizeAuthor
#16 imagefield.module-130701.patch814 bytesDarren Oh
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mr700’s picture

subscribing

quicksketch’s picture

Marked 119537 and 137577 as duplicates.

quicksketch’s picture

Marked 111433 as duplicate.

dopry’s picture

Status: Active » Postponed (maintainer needs more info)

Do you have clean urls enabled? Cleanr URL's are required for previews to function.

zigma’s picture

yes. I do have clean url enabled

ricflomag’s picture

Version: 5.x-1.1 » 5.x-2.x-dev
Priority: Normal » Critical
Status: Postponed (maintainer needs more info) » Active

Same problem here, the bug is reproducible on the most simple Dupal install:

  • using a clean Durpal 5.2 install with clean-url enabled.
  • The only contrib modules i've installed are CCK 1.6-1, Imagefield 2.x (downloaded today).
  • Directory /tmp owned by root with rwxrwxrwxt permissions, directory files owned by my user with permissions rwxrwxrwx, apachefriends' lampp 1.6 installed locally.
  • Created a basic node type called "imagen", with only one CCK field, which is an imagefield.
  • Imagefield configuration: Label = 'imagen', Max res = '800x800', Image path = 'imagenes' (directory successfully created by apache), checkbox 'required' checked, everything else left default.

I create an "Imagen" node, type a title and a body, select and upload an image (the thumbnail shows), and press "Preview". The preview only displays the title and the body of the node. The HTML code does not contains any IMG tag.

Let me known if i can provide more details.

drewish’s picture

i'm guessing you're using private file transfers?

ricflomag’s picture

No, i'm using public file tranfer (i've left all Drupal settings on their default value).

ricflomag’s picture

I've just tried private files transfers, and didn't notice any change on imagefield preview.

jonahan’s picture

*nod - here too, same problem.

It's weird in that sometimes it works and others it doesn't - no rhyme or reason to it.

I've double-checked permissions and everything.

jonahan’s picture

Ok - I think it has something to do with hook_form_alter, at least in my case.

I commented out a line and it seems to be working. Here's the offending culprit:

$form['form_array'] = array('#value' => '

'.print_r($form, true).'
', '#weight' => '99');

(It's just a test/debug statement)

Does this make -any- sense?!?
Darren Oh’s picture

This continues to be a problem, as reported in duplicate issue 163060. Commenting out the debug statement hasn't fixed it.

Darren Oh’s picture

Status: Active » Closed (works as designed)

I now see that this is by design. The module uses the menu system to provide links to files that have not been saved. It cannot provide public file paths unless clean URLs are enabled. Setting the download method to private will make it work without clean URLs.

bobdalob’s picture

This is unattractive, certainly not re-assuring to see this when previewing an image. How do you best hide altogether the 'missing' images when in node preview? Preferable if only temporary.

esolano’s picture

Version: 5.x-2.x-dev » 5.x-2.0-rc5

Hi zigma. I run into the same problem some time ago. After a lot of research, and digging into the code, I discover this:

When you upload an image and then preview it, it will be stored with a temporary name on your temp Drupal directory (since it has not been saved yet). The script that handles this is the include file.inc. The problem is that there's a php function that creates the temp file with an unique name: tempnam(). This function returns the path where the new file will be temporarily stored. The problem is that between PHP 5.2.2 and PHP 5.2.4 tempnam() changed how it handles the relative path. (check http://php.net/manual/en/function.tempnam.php#78245).

So if you have PHP 5.2.4+ then tempnam() will return the full path on your HD; not the relative path; resulting on a broken href on the preview page.

That's why it was working on our development site (PHP 5.1.2) but not on our production site (PHP 5.2.4).

This is how I solved it (includes/file.inc):
function file_check_upload($source = 'upload') {
   ...
   ...
    // Begin building file object.
    $file = new stdClass();
    $file->filename = trim(basename($_FILES["files"]["name"][$source]), '.');
   
    // Store the temp directory on a variable
    $tmp_dir = file_directory_temp();
    // Create temporary name/path for newly uploaded files
    $tmp_file_path = tempnam($tmp_dir, 'tmp_');
    // This stores the tmp filepath relative to drupal...
    // otherwise the path could be the full path on the OS directory structure
    // when using this logic: $file->filepath = tempnam(file_directory_temp(), 'tmp_');
    $file->filepath = $tmp_dir . "/" . basename($tmp_file_path);      

    $file->filemime = $_FILES["files"]["type"][$source];
   ...
   ...

I don't know if this is your case... if so, I hope this post help you!

Darren Oh’s picture

Status: Closed (works as designed) » Needs review
FileSize
814 bytes

OK, more testing shows that this cannot have been by design and is not dependent on the PHP version. The attached patch should fix it for everyone.

SocialNicheGuru’s picture

subscribing

dopry’s picture

Status: Needs review » Closed (fixed)

@darrenoh, that patch isn't against DRUPAL-5--2... and the menu deals with converting that url to the path to the preview...

@all: open new issues, and your own if you're still having problems. make sure you note which version of imagefield you are using. I'm not sure which issue to address in this thread. I get previews with the latest RC.

Darren Oh’s picture

Version: 5.x-2.0-rc5 » 5.x-1.x-dev
Status: Closed (fixed) » Needs review

This issue is for the DRUPAL-5 branch. It got hijacked in comment #6. Without this patch, the menu system cannot find a match when private downloads are enabled because file_create_url() prepends an extra "system/files/" to the URL. This will only affect images uploaded after private downloads are enabled.

Darren Oh’s picture

Let me summarize the problems this patch solves:

  1. When the download method is private, file_create_url() prepends an extra "system/files/" to the file path, so the menu system cannot find a match for the path.
  2. When the download method is public and the site does not support clean URLs, the menu system will not even be used. The file path will point to a file that does not exist.

In both cases, it will be impossible to see the image in the node preview. I do not know if this is an issue in the DRUPAL-5--2 branch, but I will create a separate issue if it is.

32940stf’s picture

subscribing

Darren Oh’s picture

Patch for DRUPAL-5--2 is in issue 230848.

khanshakeeb’s picture

okay guys i resolve this problem by making tmp dir under drupal files folder like files->tmp...
and then make some changes into imagefield.module simple nothing to do alots of changes and also i recommended never make changes into drupal core files ...

function _imagefield_widget_prepare_form_values($node, $field, &$node_field) {
$fieldname = $field['field_name'];
// clean up the session if we weren't posted.
if (!count($_POST)) {
imagefield_clear_session();
}

// Attach new files
if ($file = file_check_upload($fieldname . '_upload')) {
/* here i take image url which is now in tmp dir */
$img="tmp/".basename($file->filepath);

$file = (array)$file;
if (strpos($file['filemime'],'image') !== FALSE) {
$file = _imagefield_scale_image($file, $field['widget']['max_resolution']);

// Create the filepath for the image preview
$filepath = $img;
/*for the time being i just comment this line */
//file_create_filename($file['filename'], file_create_path($field['widget']['image_path']));

if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
if (strpos($filepath, file_directory_path()) !== FALSE) {
$filepath = trim(substr($filepath, strlen(file_directory_path())), '\\/');
}
$filepath = 'system/files/' . $filepath;
}

$file['fid'] = 'upload';
$file['preview'] = $filepath;

// If a single field, mark any other images for deletion and delete files in session
if (!$field['multiple']) {
if (is_array($node_field)) {
foreach ($node_field as $delta => $session_file) {
$node_field[$delta]['flags']['delete'] = TRUE;
}
}
imagefield_clear_field_session($fieldname);
}
// Add the file to the session
$file_id = count($node_field) + count($_SESSION['imagefield'][$fieldname]);
$_SESSION['imagefield'][$fieldname][$file_id] = $file;
}
}

// Load files from preview state. before committing actions.
if (is_array($_SESSION['imagefield'][$fieldname]) && count($_SESSION['imagefield'][$fieldname])) {

foreach($_SESSION['imagefield'][$fieldname] as $delta => $file) {
$node_field[] = $file;
}
}
}

Darren Oh’s picture

Let me point out that there is a patch in #16 waiting for review. This will not be fixed until someone has tested the patch.

dopry’s picture

@darrenOh should be committed now... I didn't test.. so I'm trusting you on this one. :)

minesota’s picture

Subscribing

dopry’s picture

Status: Needs review » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

mrfelton’s picture

Status: Closed (fixed) » Active

I get the same problem. I tried with the latest 5.x-1.x-dev version as well as 5.x-2.0. The temporary file is created in the location I specified, but the img element on the preview page points to this file with an absolute system url (//home/tom/public_html/drupal-5.x/files/tmp/tmp_Qk22YW) rather than a relative (or even an absolute) web accessible url.

kamleshpatidar’s picture

Hi mrfelton,

I am facing the same situation

"but the img element on the preview page points to this file with an absolute system url (//home/tom/public_html/drupal-5.x/files/tmp/tmp_Qk22YW) rather than a relative (or even an absolute) web accessible url."

have you find out any solution for this?

Best,

Kamlesh

quicksketch’s picture

Priority: Critical » Normal

mrfelton and kamleshpatidar: The problem you describe might be because the system does not support Clean URLs. Darren Oh provided a patch for this in #230848: Node Preview Errors, not generating appropriate URLS when rewrite engine off..

quicksketch’s picture

Version: 5.x-1.x-dev » 5.x-2.4

Also, the 1.x version is no longer supported. If the problem has been fixed in the latest 2.x version please close.

quicksketch’s picture

Status: Active » Closed (fixed)

Let's close out this long and winding thread. For any users of 2.6 and higher, a new issue has been opened at #405970: Unsaved nodes: images no longer appear in preview on upgrade to 2.6.

abhisheknagar’s picture

Version: 5.x-2.4 » 6.x-3.0-beta3

image not shown in preview or in content after saving after i upgraded to imagefield-6.x-3.0-beta3