Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8036543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:39:17+00:00 2026-06-05T02:39:17+00:00

I have somehow implemented UPLOADIFIVE in my CakePHP application. Everything seems to work great

  • 0

I have somehow implemented UPLOADIFIVE in my CakePHP application. Everything seems to work great including uploading multiple files and inserting the correct information in the Database.

Based on the following code, I would like to UPLOAD AND SAVE EVERY FILE WITH A RANDOM NAME TAKING INTO ACCOUNT THE CURRENT DATE OR SOMETHING SIMILAR.

How could I accomplish this?

In my Photos Controller I have the following function:

// This function is called at every file upload. It uploads the file onto the server
// and save the corresponding image name, etc, to the database table `photos`.
function upload() {
    $uploadDir = '/img/uploads/photos/';

    if (!empty($_FILES)) {
        debug($_FILES);

        $tempFile   = $_FILES['Filedata']['tmp_name'][0];
        $uploadDir  = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
        $targetFile = $uploadDir . $_FILES['Filedata']['name'][0];

        // Validate the file type
        $fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions
        $fileParts = pathinfo($_FILES['Filedata']['name'][0]);

        // Validate the filetype
        if (in_array($fileParts['extension'], $fileTypes)) {

            // Save the file
            move_uploaded_file($tempFile,$targetFile);

            $_POST['image'] = $_FILES['Filedata']['name'][0];           

            $this->Photo->create();
            if ($this->Photo->save($_POST)) {
                $this->Session->setFlash($targetFile, 'default', array('class' => 'alert_success'));
                $this->redirect(array('action' => 'index'));
            }
        } else {
            // The file type wasn't allowed
            //echo 'Invalid file type.';
            $this->Session->setFlash(__('The photo could not be saved. Please, try again.', true));
        }
    }
}

In my View file - admin_add.ctp I have added the following function

$('#file_upload').uploadifive({
    'auto' : false,
    'uploadScript' : '/photos/upload',
    'buttonText' : 'BROWSE FILES',
    'method'   : 'post',
    'onAddQueueItem' : function(file) {
        this.data('uploadifive').settings.formData = { 'photocategory_id' : $('#PhotoPhotocategoryId').val() };
    }
}); 


<input type="file" name="file_upload" id="file_upload" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:39:19+00:00Added an answer on June 5, 2026 at 2:39 am
    function upload() {
    $uploadDir = '/img/uploads/photos/';
    
    if (!empty($_FILES)) {
        debug($_FILES);
    
     //   $tempFile   = $_FILES['Filedata']['tmp_name'][0];
        $uploadDir  = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
        $targetFile = $uploadDir . $_FILES['Filedata']['name'][0];
    
        // Validate the file type
        $fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions
        $fileParts = pathinfo($_FILES['Filedata']['name'][0]);
    
        // Validate the filetype
        if (in_array($fileParts['extension'], $fileTypes)) {
    
            // Save the file
    
         $tempFile    = time()."_".basename($_FILES['Filedata']['name'][0]);
         $_POST['image'] = $tempFile;
    
            move_uploaded_file($tempFile,$targetFile);
    
    
    
            $this->Photo->create();
            if ($this->Photo->save($_POST)) {
                $this->Session->setFlash($targetFile, 'default', array('class' => 'alert_success'));
                $this->redirect(array('action' => 'index'));
            }
        } else {
            // The file type wasn't allowed
            //echo 'Invalid file type.';
            $this->Session->setFlash(__('The photo could not be saved. Please, try again.', true));
        }
       }
       } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I somehow have the feeling that modern systems, including runtime libraries, this exception handler
I have implemented drag and drop in my application, but am having some difficulty
I have implemented some computationaly heavy functions into my application. Depending on the type
I had implemented a wpf combobox into a winform and now have to somehow
The problem that I have is somehow very specific. I have to implement a
I have somehow managed to break my infopath form :( When I try to
I have somehow managed to get a really screwed up Eclipse project. I have
I had this code working before, but have somehow deleted it as I was
I have a somehow funny issue. While trying to understand why a certain website
http://www.kidzoneapp.com/uses.html In this app, they somehow have an ability to protect users home button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.