/    Sign up×
Community /Pin to ProfileBookmark

move_uploaded_file(..)

hi all members,

using the PHP fonction [B]move_uploaded_file(..)[/B] is it possible to choose the name onder which you are storing the uploaded file on the destination directory?

Example: you upload from your PC the file [B]myfile.gif[/B] and on the destination direstion you use as name of the file [B]othername.gif[/B]

thank you in advance

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@dreamcatcherOct 19.2004 — What you need is the rename() function.

[URL=http://uk.php.net/manual/en/function.rename.php]http://uk.php.net/manual/en/function.rename.php[/URL]
Copy linkTweet thisAlerts:
@osxboyOct 19.2004 — or

[PHP

move_uploaded_file ( $HTTP_POST_FILES{filename]['tmp_name'], "http://www.url.com/directory/filename.ext")

[/code]

Obvioulsy you need to add error checking code.
Copy linkTweet thisAlerts:
@pyroOct 19.2004 — The destination filename is the second paramater of the [URL=http://www.php.net/manual/en/function.move-uploaded-file.php]move_uploaded_file[/URL] function. You can also take a look [URL=http://www.php.net/manual/en/features.file-upload.php]here[/URL] for more information on handling file uploads.
Copy linkTweet thisAlerts:
@faamugolauthorOct 19.2004 — thank you very much for all your answers..

I want to be more clear.

When a visitor of my site wants to register , he can also upload his picture(photo). But I encourred the following problem. When a previous visitor has already register with the same name for his picture, the last one overwrites the first one.

Waht I need is the following:

When a visitor upload his picture, I make a test, if the filename already exists on the server, I juste add somes chars to the second, so to make a difference between the two picture.

Or anyone has another idea ?


thank you in advance for your answer
Copy linkTweet thisAlerts:
@pyroOct 19.2004 — Take a look at the [URL=http://www.php.net/manual/en/function.file-exists.php]file_exists[/URL] function.
Copy linkTweet thisAlerts:
@yunaOct 19.2004 — Regardless of what the uploader calls the file, you need to be in control of how things are named on your server. The easiest solution would be to use the person's registered ID, since that has to be unique for other things to work correctly. So, for instance, if I register as "yuna" and upload "myphoto.jpg," you could store it as "yuna.jpg" and link to it accordingly.

I've even used Unix timestamps as filenames since they're so likely to be unique. There would be a conflict only in the case of two simultaneous submissions within the same second. None of the sites I've developed handle traffic at that rate of speed. Since all the person's information is in the database, it doesn't matter what I call the file. The database record makes the appropriate connections between the user and the filename I've chosen.
Copy linkTweet thisAlerts:
@dreamcatcherOct 19.2004 — Another solution is to make the field that holds the photo name in your database UNIQUE. This will prevent duplications. When you do your SQL query, if it returns false, inform the user that the image already exists.
Copy linkTweet thisAlerts:
@faamugolauthorOct 19.2004 — All of you lots of thanks for the apply you provid...they are very helpful..

The idea of [B]dreamcatcher[/B] seems to be the solution of my problems.. I let you know when ever I 'll come out..

thank you ones
×

Success!

Help @faamugol spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...