Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

55 users online



Rename Uploaded file

Rename Uploaded file

Currently viewing this thread: 1 (0 members and 1 guests)


stp

stp

Im Jackson And I PWN StickThemePark.Com
Status: Offline!

Rename Uploaded file

Ok ive got a fileuploader and I expect that im gonna have a problem with people uploading files with the same name even though I made it so it would tell the user if theres a file with that name.

What I want to do is have $filename-$count.swf I was wondering how I can rename the file from just blah.swf to blah-13.swf on upload.

$filename would be the filename from the orginal file and $count would be how for how many uploads there been going up each time

Any ideas?

___________________

-=STP=- StickThemePark.Com

BigToach

BigToach

Neversidian
Status: Offline!

you can either scan the directory and see how many files you have, you can store the number in a text file or a mysql db just like a hit counter, but for the downloads, or if you dont want the numbers to be in order you can use a timestamp, the timestamp is the easiest but it puts a 10 digit number in the filename.

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

stp

stp

Im Jackson And I PWN StickThemePark.Com
Status: Offline!

I already have a line that counts how many movies have been uploaded I just need to figure out how you rename a file on upload

___________________

-=STP=- StickThemePark.Com

dafrabbit

dafrabbit

Neverside Newbie
Status: Offline!

rename() perhaps? Search in the PHP documentation ext time for this kind of question.

BigToach

BigToach

Neversidian
Status: Offline!

well then when u save the filename just put the unique key at the beginning of it...

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

vvuiverine

vvuiverine

Status: Offline!

how about this?

PHP:

<?php

$count 
"0";
$filename $_FILES['thefile']['name'];
$dir opendir("./uploaded");
$nondupname explode(".",$filename);
while(
false !== ($files readdir($dir))) {
    if(
$filename == $files){
        
$count++;        
        
$filename $nondupname[0].$count.".".$nondupname[1];
        }
    }
    
copy($_FILES['thefile']'tmp_name'],"uploaded//".$filename);

?>

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0079 seconds.