class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
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...
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
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
great script, but there is one thing I have not been able to solve and its driving me crazy.
this is my script:
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?
Please re-read the part of the documentation showing which variables you can set/read before and after calling process()
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
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
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.