You are here: Re: tricky php, can anyone help « PHP Programming Language « IT news, forums, messages
Re: tricky php, can anyone help

Posted by matpac4 on 10/02/62 12:00

On Jan 16, 8:26 am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.com> wrote:
> 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.

Thanks Marlin, Luuk and C. for your replies.

I'm trying to work with them but I am a beginner and this is a tricky
problem.

C. - a couple of things, I'd like to keep it simple with a single
directory for the moment because other things (code) rely on this fact
at the moment.

Also I'm only allowing users to upload images. I just need a certain
php file to be created everytime the form is submit. And I need it to
have a sequentially increasing number for it's name taht is somehow
kept on a table or sourced from a table so that I can reference this
number to the submitters name in future.


I'll look through the code again, just not sure if copy is best if I
already have the file I want creating on the server, and just to copy
it and rename it on form submit.


.... I've just been thinking and maybe I have to make this form a 2
step process, maybe ask them half their details, then click next (this
will create a row on another tbl containg 'persons name', 'unique
incremental file number' (issued on input to db) and there telephone
or something...
....the second part of the form will look down the table for the
'unique incremental filenumber' where persons name = bob, and
telephone = 2123456789 (and it will already have these details (bob
and tel) from the first half of the form) - then it will have a unique
id for that form submission and the number retrieved can then be used
to rename the copied file on the server and rename the attached
image...

Hassle that it's a 2 step form but might work - what do you think?

If there's a way for this to work then I just need to figure out how
to copy a file already on the server to a new location and rename
(I'll check your suggestion Luuk)

Thanks

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация