|
Posted by C. (http://symcbean.blogspot.com/) on 10/02/04 12:00
On 16 Jan, 08:51, "Luuk" <l...@invalid.lan> wrote:
> <matp...@gmail.com> schreef in berichtnews:d3dba30e-9464-4818-af9a-9732133bf4c7@m34g2000hsb.googlegroups.com...
>
>
>
> > On Jan 16, 2:59 am, Marlin Forbes <"marlinf <AT> datashaman <POINT>
> > wrote:
> >> Hi there,
>
> >> matp...@gmail.com wrote:
> >> > But I need a way of getting the unique id to the file name and am not
> >> > sure of a way to do this, especially with the problem of when several
> >> > people are completing the form at the same time. I need to make sure
> >> > that the number given to the duplicated .php file isn't associated
> >> > more than once.
>
> >> When handling uploaded files in PHP, the $_FILES array holds a variable:
>
> >> $_FILES['userfile']['tmp_name']
>
> >> The tmp_name is guaranteed to be unique within the folder where the
> >> temporary uploaded files are stored. You could strip the filename
> >> portion of that out and use it in your destination folder.
>
Certainly you shouldn't preallocate names and store them in the form -
that's just asking for trouble. If you're using MySQL and have an
autoincrement id column, then you can find the value used by the last
insert with mysql_insert_id().
> >> For more details on file uploads and the temp folder handling, see the
> >> entry under Features/Handling file uploads in the manual.
....
> > This process of uploading the attachment, duplicating/copying and
> > renaming the php file on server and entering the table contents into
> > the DB could happen thousands of times - I would ideally like the
> > names of the php pages to be 1001.php, 1002.php, 1003.php etc. (and
> > the associated attachment uploads to be 1001.gif, 1002.gif, 1003.gif
>
If you've got a large number of files, you should definitely think
about splitting this into directories:
function get_dir($filenumber, $level)
{
$out='';
for ($x=0; $x<$level; $x++) {
$out.=substr($filenumber,$x,1) . '/';
}
$out.=substr($filenumber,$level);
return($out);
}
.....
get_dir(10203, 3) = '1/0/2/03'
get_dir('94522378.gif', 4) = '9/4/5/2/2378.gif'
> > You can see how I'm trying to copy this folder over and rename it.
> > Eventually I'd like to substitute 'newname.php' with '$uniqueID.php'
>
!!!
You're going to let people upload php code to your server! Be very
careful!! If its inside the doc root and you don't reconfigure your
webserver it means the code wil be executed!!!
> try the example onhttp://nl3.php.net/manual/en/function.copy.php
> <?php
> $file = 'example.txt';
> $newfile = 'example.txt.bak';
>
> if (!copy($file, $newfile)) {
> echo "failed to copy $file...\n";}
>
> ?>
no - use move_uploaded_file() instead - RTFM
C.
Navigation:
[Reply to this message]
|