Jump to content

img->size() irregular behaviour


muzzer
 Share

Recommended Posts

if( wire('input')->post->submit )
{
      $tmp_file = $_FILES['imageFile']['tmp_name'];
   
      $upload_path = 'c:/wamp/tmp/';
      
      // new wire upload
      $u = new WireUpload( 'imageFile' );
      $u->setMaxFiles( 1 );
      $u->setDestinationPath( $upload_path );
      $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png'));

         // execute upload and check for errors
      $files = $u->execute();

      if(!$u->getErrors()){
         // create the new page to add the images
         $uploadpage = $pg = wire('pages')->get('/listings/')->find("listingId={$_GET['lid']}")->first();
         $uploadpage->of(false);
         $uploadpage->listingImages = $upload_path . $files[0];
         $uploadpage->save();
         $uploadpage->of(true);
         
         $imagePg = $pg = wire('pages')->get('/listings/')->find("listingId={$_GET['lid']}")->first();
         $img = $imagePg->listingImages->last();
         $img->size(1024,768); 
      }
}

The $img->size() function works most of the time but occasionally returns an error 

Rename: Access is denied. (code: 5) - /domain/wire/core/ImageSizer.php:401

where the result is a new file: "img.1024x768_tmp.jpg" but no "img.1024x768.jpg"

Permissions and space are not an issue. The same file works one time and not the next etc, very irregular. It does this with several different files so no file corruption issues or anything like that.

Anyone seen this before?

Link to comment
Share on other sites

A full sample error message:

rename(C:/wamp/www/testdomain/site/assets/files/3077/blenheim.172x129_tmp.jpg,C:/wamp/www/testdomain/site/assets/files/3077/blenheim.172x129.jpg): Access is denied. (code: 5) - /testdomain/wire/core/ImageSizer.php:401

It seems imageSizer takes "image.jpg", copies it to "image.widthxheight_tmp.jpg" file. It then resizes this file to the specified width and height dimensions and then renames it to image.widthxheight.jpg. It is the last part that is failing.

As a side note; I'm using the above method as it appears there is no maxWidth and maxHeight parameters in the wireUpload class. I'm uploading images from the frontend rather then uploading images from the admin backend which I normally do and from where max dimensions can be specified - is this the standard method when trying to achieve a max image dimensions from a frontend upload?

.

Link to comment
Share on other sites

Thanks Apeisa, yeah, permissions and diskspace was the first thing I checked. Next was trying different files and filesizes ranging from 1-9Mb. All would work more often than not, probobly 30% of the time they failed. Tried multiple browsers, cleared cache and cookies etc....

It's odd because it copies and resizes the file ok, which reinforces the problem not being permissions or lack of memory yeah?, it's just the rename that fails. The filenames are all regular characters.

Link to comment
Share on other sites

OK, thanks again Apeisa, that's one direction I didn't even think of looking in.

There are a few other cases of definite identical problems on Win, so I'm putting it down to being a Win issue for now. Once I have hosting setup on a linux server I'll have another look at it.

Perhaps it's time to re-dirch Windows and reinstall Linux Mint. Oh why did I ever leave you Minty  :'(

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...