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 7624243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:54:44+00:00 2026-05-31T04:54:44+00:00

Hi Im trying to create a file upload system where I am able to

  • 0

Hi Im trying to create a file upload system where I am able to upload a file and it will change the filename to the MYSQL ID that has been uploaded onto the table.
This is my code…

function add() {
    if (!empty($this->data)) {
        $this->Upload->create();
        if ($this->uploadFile() && $this->Upload->save($this->data)) {
            $this->Session->setFlash(__('<p class="uploadflash">The upload has been saved</p>', true));
            $this->redirect(array('action' => 'add'));
        } else {
            $this->Session->setFlash(__('<p class="uploadflash">The upload could not be saved. Please, try again.</p>', true));
        }
    }
        }

function uploadFile() {
    $file = $this->request->data['Upload']['file'];
    if ($file['error'] === UPLOAD_ERR_OK) {
        if (move_uploaded_file($file['tmp_name'], APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4')) {
            $this->Upload->save($this->data);
            return true;
        }
    }
    return false;
}

However the file is not being uploaded to the directory but the information is being uploaded to the sql tabe.

I don’t see why this function $this->Upload->id is not working for the file rename?
If I put it in speech marks then it renames the file to “$this->Upload->id.mp4” but I want it to be more like 114.mp4 if thats the field where the information has being saved.
Anybody have any ideas?

Thanks in advance

  • 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-05-31T04:54:45+00:00Added an answer on May 31, 2026 at 4:54 am

    You need to save first.
    $this->Upload->id is empty in your case.

    For your interest:
    $this->Upload->create(); clears $this->Upload->id

    See also:

    http://api20.cakephp.org/class/model#method-Modelcreate
    http://api20.cakephp.org/view_source/model#line-1381

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a script that will upload a file to a website.
I am trying to create a file upload field that has a little bit
I am trying to create a system that enables the admin to upload a
I'm trying to create a Zip file from .Net that can be read from
I am trying to create a php file that adds a user and create
js.I am trying to create a file upload using node.js and mongodb.I am getting
I'm trying to create a simple file upload form for my website. I'm using
I am trying to create a system which enables user to upload a zipfile,
I am trying to set up a system in which user uploaded files will
I am trying to create a simple screen where the file selected for upload

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.