Reply to Re: How to only upload the renamed file

Re: How to only upload the renamed file new!
by IT Larry, 16 years, 11 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

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important