how to omit file_dst_name_ext

See all posts Reply

how to omit file_dst_name_ext new!
by Eli, 13 years, 6 months ago
Hi,

great script, but there is one thing I have not been able to solve and its driving me crazy.

this is my script:
if ($handle->uploaded) {
  $handle->file_dst_name           = str_replace('.' . $handle->file_dst_name_ext, '', $_FILES['Filedata']['name']);
  $handle->file_new_name_body      = $handle->file_dst_name;
  $handle->file_safe_name          = false;

  $handle->Process($dir_dest);

  // we now process the image a second time, with some other settings
  $handle->image_resize            = true; // we resize the image
  $handle->image_ratio_x           = true; // we want to keep the ratio of the width
  $handle->image_y                 = 100; // we set the height to 150px, keeping the width automatic
  $handle->file_dst_name           = str_replace('.' . $handle->file_dst_name_ext, '', $_FILES['Filedata']['name']);
  $handle->file_new_name_body      = $handle->file_dst_name;
  $handle->file_safe_name          = false;
  $handle->file_name_body_pre      = 'thumb_'; // this adds -thumb at the end of the file to let you know its a thumbnail

  $handle->Process($dir_dest.'/thumbs/');

  // we delete the temporary files
  $handle-> Clean();
}

ok, so my problem is that on the first pass the file is uploaded looks like this picturejpg.jpg but on the second pass when I make my thumbnail it does it correct and outputs like this: thumb_picture.jpg

I can't figure out why on the first pass it won't remove the .jpg from the file.

without any processing and leave it at its defaults the files are uploaded like this

picturejpg.jpg
thumb_picturejpg.jpg

so I tried to do a string replace to remove the .jpg, it works for the second pass but now the first...


any ideas?Reply
Re: how to omit file_dst_name_ext new!
by colin, 13 years, 6 months ago
You cannot read nor set file_dst_* before calling process(). You can only read file_src_* variables. And there is no need to read $_FILES array.

Please re-read the part of the documentation showing which variables you can set/read before and after calling process()Reply
Re: how to omit file_src_name_ext new!
by Eli, 13 years, 6 months ago
i have file arrays because I have this script being executed with a flash uploader I have which also supports multiple files to be uploaded at once.

The file is uploaded via flash, then applied a session_id name which can be accessed by $_FILE['Filedata']['tmp_name'] that is the file in the /tmp folder on my server.

Your script picks up to make sure that the file is there when calling
$handle = new Upload($_FILES['Filedata']['tmp_name']);

then I take the file and give it a new name using the file_new_name_body to the actual name of the file this in my case
$handle->file_new_name_body = $_FILES['Filedata']['name'];

so now the file looks like aoz.jpg instead of phpHuYkOd.jpg

then I call process and upload the file to the server with the new file name. But at this stage the file is now uploaded to look like this
aozjpg.jpg

This is where I am stuck, I followed the documentation but it isn't working for me. I'm sorry for not being a creative in PHP to be able to solve this on my own.

I also changed all my file_dst to file_src in my first process but that didn't help.Reply
Re: how to omit file_src_name_ext new!
by colin, 13 years, 5 months ago
You should output the log for each call to process(), in order to see how the file is being renamed.Reply