Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot End Filename In Variable #48

Closed
Jongosi opened this issue Sep 6, 2016 · 8 comments
Closed

Cannot End Filename In Variable #48

Jongosi opened this issue Sep 6, 2016 · 8 comments
Labels

Comments

@Jongosi
Copy link

Jongosi commented Sep 6, 2016

This issue occurs when you try to save a filename ending in a variable.

The following does not work:

$handle->file_new_name_body = "img_{$var}";

But this does work:

$handle->file_new_name_body = "img_{$var}_"; // <-- note the underscore

In the first instance, the class tries to rename the filename by appending an integer suffix; _1, _2 and so on, between the supplied filename and the file extension. In the above example, if the value of $var = 'test'; the resulting filename will be img_test_1.jpg

If I set the option:

$handle->file_auto_rename = false;

then the file is not saved at all.

@Jongosi Jongosi changed the title Cannot use variables in filename Cannot End Filename In Variable Sep 6, 2016
@verot
Copy link
Owner

verot commented Sep 6, 2016

I don't understand what you mean.

This:

$var = 'test';
$handle->file_new_name_body = "img_{$var}";

Is the same as this:

$handle->file_new_name_body = "img_test";

So the fact that there is a variable interpolation doesn't matter.

And then, if you have:

$handle->file_new_name_body = "img_test";

You get as images:

img_test.jpg
img_test_1.jpg
img_test_2.jpg...

Or, if you have:

$handle->file_new_name_body = "img_test_";

You get as images:

img_test_.jpg
img_test__1.jpg
img_test__2.jpg...

I don't see where the problem is...

@verot verot added the invalid label Sep 6, 2016
@Jongosi
Copy link
Author

Jongosi commented Sep 6, 2016

I never get an upload named:

img_test.jpg

It's always img_test_1.jpg then subsequent uploads are:

img_test_2.jpg
img_test_3.jpg
img_test_4.jpg

and so on.

Additionally, if I set

$handle->file_auto_rename = false;

Then nothing is saved at all.

Thanks for an awesome class by the way, and all your hard work!

@verot
Copy link
Owner

verot commented Sep 6, 2016

Can you copy here the logs produced by the class for each of your attempts you are describing above?

@Jongosi
Copy link
Author

Jongosi commented Sep 6, 2016

I just got this to work by removing the call to $handle->clean();:

$handle = new upload( $filePath );

if ( $handle->uploaded ) {
    // main image

    $handle->file_new_name_body = (string) $pathMain;
    $handle->allowed            = array('image/*');
    $handle->image_resize       = true;
    $handle->image_no_enlarging = true;
    $handle->jpeg_quality       = 50;
    $handle->image_x            = 512;
    $handle->image_y            = 288;
    $handle->file_overwrite     = true;
    $handle->file_auto_rename   = false;
    $handle->process( $imgPath );

    if ( !$handle->processed ) {
        $errors[] = $handle->error;
    }

    // thumb

    $handle->file_new_name_body = (string) $pathThumb;
    $handle->allowed            = array('image/*');
    $handle->image_resize       = true;
    $handle->image_no_enlarging = true;
    $handle->jpeg_quality       = 50;
    $handle->image_x            = 192;
    $handle->image_y            = 108;
    $handle->file_overwrite     = true;
    $handle->file_auto_rename   = false;
    $handle->process( $imgPath );

    if ( !$handle->processed ) {
        $errors[] = $handle->error;
    }

    $handle->clean(); // <-- removed this and filenames are working now
}

@verot
Copy link
Owner

verot commented Sep 6, 2016

This shouldn't have an effect. Can you copy here the logs produced by the class, with and without  $handle->clean()?

@Jongosi
Copy link
Author

Jongosi commented Sep 6, 2016

Can you tell me how to get the log contents? I can't see anything in the docs about logging? Thanks.

@verot
Copy link
Owner

verot commented Sep 6, 2016

Just add this at the end of your code: echo $handle->log;

@verot verot closed this as completed Sep 19, 2016
@danman12345
Copy link

I got the same problem. $handle-> clean(); solved the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants