tags:

views:

144

answers:

2

Hello,

I'm using the Uploadify jQuery plugin for PHP to upload a file. One thing I am stuck on is that I need to be able to rename the file being uploaded so that I can post that information to my script that inserts data into the mysql database. Can anyone please advise on how to do this?

Thanks, Jake

A: 

If you use uploadify.php just go right before the function move_uploaded_files and change the target name.

Anyways you do it this should work. Post the code you have if you want a more detailed answer.

Iznogood
What you're saying is exactly what I was thinking, however, the code that inserts data such as the title of the post and description are run through another .php file which does the actual query to the database. Any thoughts?
Jake
What? Thats not what you asked at all! Post the actual code you have. For sure when move_uploaded_files happens the filename is there and you should be able to track down when its passed to the other script and then rename it.
Iznogood
A: 
This will put file in new folder with same file name as source file

$source   = $_FILES['Filedata']['tmp_name'];
$filename = $_FILES['Filedata']['name'];
$newPath = $folder.'/'.$filename;
rename($source, $newPath);

/*----------------------*/

to have a new filename
    function getExtension($path)
    {
        $result = substr(strtolower(strrchr($path, '.')), 1);
        $result = preg_replace('/^([a-zA-Z]+)[^a-zA-Z].*/', '$1', $result);
        if ($result === 'jpeg' || empty($result) === true) {
            $result = 'jpg';
        }
        return $result;
    }

$source   = $_FILES['Filedata']['tmp_name'];
$filename = $_FILES['Filedata']['name'];
$newfileName=$folder."/"."abc".getExtension($filename);
rename($source, $newfileName);
JapanPro