How to only upload the renamed file

See all posts Reply

How to only upload the renamed file new!
by IT Larry, 16 years, 4 months ago
How do I shut off from uploading the original named file from being uploaded and only upload the one that I have controlled the naming on?

I want to totally control the name of the file when it is uploaded and I don't want to clutter up the folder with the original if it is named different from my naming convention.Reply
Re: How to only upload the renamed file new!
by colin, 16 years, 4 months ago
You can set the following setting:
$foo->file_new_name_body = 'my_filename';
which will result in a file called for instance my_filename.jpg or my_filename_1.jpg.Reply
Re: How to only upload the renamed file new!
by IT Larry, 16 years, 4 months ago
I already have that and it works, however, it ALSO uploads the actual file, so what I end up with is 2 files, the one with the new name body and the original file, for example:

my_filename.pdf AND whatever_the_real_file_name_was.pdf.

I only want ONE file uploaded - my_filename.pdf.

Is that do-able?Reply
Re: How to only upload the renamed file new!
by colin, 16 years, 4 months ago
It shouldn't be doing that. Can you paste here the results of $foo->log and your code?Reply
Re: How to only upload the renamed file new!
by IT Larry, 16 years, 4 months ago
Here's the code. I don't see any log anywhere on the server.
// ---------- SIMPLE UPLOAD ----------
$name_body="Closing_".$account_id;
// we create an instance of the class, giving as argument the PHP object 
// corresponding to the file field from the form
// All the uploads are accessible from the PHP object $_FILES
$handle = new Upload($_FILES['my_field']);
$handle->file_new_name_body = $name_body;
$handle->file_new_name_ext = 'pdf';
$handle->allowed = array('application/pdf');
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
    // yes, the file is on the server
    // now, we start the upload 'process'. That is, to copy the uploaded file
    // from its temporary location to the wanted location
    // It could be something like $handle->Process('/home/www/my_uploads/');
    $handle->Process('./efiles/');
    
    // we check if everything went OK
    if ($handle->processed) {
        // everything was fine !
        echo '  File uploaded with success';
        echo '  ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB';
        echo '  Link to the archive file just uploaded: file_dst_name';
    } else {
        // one error occured
        echo '  file not uploaded to the wanted location';
        echo '  Error: ' . $handle->error . '';
    }

    // we copy the file a second time
    $handle->Process('./efiles/');
    
    // we check if everything went OK
    if ($handle->processed) {
        // everything was fine !
        //echo '  File uploaded with success';
        //echo '' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB';
        //echo '  Link to the actual file just uploaded: file_dst_name';
    } else {
        // one error occured
        echo '  file not uploaded to the wanted location';
        echo '  Error: ' . $handle->error . '';
    }
    
    // we delete the temporary files
    $handle-> Clean();

} else {
    // if we're here, the upload file failed for some reasons
    // i.e. the server didn't receive the file
    echo '  file not uploaded on the server';
    echo '  Error: ' . $handle->error . '';
}//end else
Reply
Re: How to only upload the renamed file new!
by colin, 16 years, 4 months ago
You have to set up these parameters before each call to process():
$handle->file_new_name_body = $name_body;
$handle->file_new_name_ext = 'pdf';

Every time you call process(), you reset all parameters, so you can start from scratch to do something else with the file.

As for the log, simply output $handle->log after calling $handle->process().Reply
Re: How to only upload the renamed file new!
by IT Larry, 16 years, 4 months ago
Okay, I did that, and now I get 2 files, one called Closing_XXXXX.pdf and one named Closing_XXXXX_1.pdf.

How do I get ONE? Why does it upload twice?

PS: do you know that most of the time, the little graphic code box is only wide enough to show 4 of the five image characters to verify adding to the blog? It takes 4 or 5 trys to get one that is readable. It needs to be wider.Reply
Re: How to only upload the renamed file new!
by colin, 16 years, 4 months ago
You are getting two files because you are calling process() twice!Reply
Re: How to only upload the renamed file new!
by IT Larry, 16 years, 4 months ago
AHA. so I didn't need to copy the whole Simple Upload script part of upload.php.

Thanks.

Sorry to be such a pain, and thanks for all your hard work.

And also, you should get some sleep, according to my calculations it is 1:30 in the AM where you are, whereas here in Georgia, US it is 7:30PM. Of course, I realize that us geek coders do stay up until all hours.

Thanks again.Reply
Re: How to only upload the renamed file new!
by colin, 16 years, 4 months ago
No problems. The sample script is just to give an example of implementation.

Thank for pointing out the issue with the CAPTCHA. it should be fixed now.

As for the time, yes, it's late, but it is only the start of the night ;)Reply
Re: How to only upload the renamed file new!
by IT Larry, 16 years, 4 months ago
Yeah, I notice you got that fixed. Isn't it GREAT working with php, linux and other NON Microsoft stuff that really works!

Slowly, I think the US will start coming around to the fact that MS is not really the best answer. That is already become a fact in the EU.

Have a pleasant and productive night.

Best regards.Reply