467,894 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

tricky php, can anyone help

I'm a bit stuck! Please can someone help.

Here's what I'm trying to build:

1. Webform which puts variables into a database (each with unique ID
field)
2. Webform also allows attachment which uploads the file to specific
directory
3. On submission of webform for a file on the directory to be
duplicated and renamed "unique ID".php and placed in a specific folder
I have completed 1 + 2, but am stuck with the 3rd.

A few of my thoughts on this are:

Regarding the creation/duplication and renaming of the .php file,
maybe I can treat this as a file upload but from the server - a little
confusing, but I'm thinking along the lines of how the file upload
works above, except this would be a hidden field in the submission
form, and I'd have to set the path to the file on the server in the
hidden field also - not sure how to do this though...

....Plus this also leaves the problem of giving the duplicated file
it's related "uniqueid.php" name.

The contents of the php file that I'm wanting to create/duplicate will
all be the same code each time the form is submitted. I will have code
in these files which reads the file name and displays the proper stuff
related to the file name.

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.

If anyone can help me with any bitesize portion of this I'd appreciate
it.

Thanks for any help
Jan 16 '08 #1
  • viewed: 1143
Share:
4 Replies
Hi there,

ma*****@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.

For more details on file uploads and the temp folder handling, see the
entry under Features/Handling file uploads in the manual.

Or alternately, you can use the php function tempname, detailed under
Filesystem Functions in the manual.

Regards,
Marlin Forbes
Data Shaman
datashaman.com
Jan 16 '08 #2

"C. (http://symcbean.blogspot.com/)" <co************@gmail.comschreef in
bericht
news:95**********************************@u10g2000 prn.googlegroups.com...
>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.
it was the manual i quoted......
OP was using copy() and was wondering why it did not work,
not questioning himself if there was another (or better) option.

;-)

Jan 16 '08 #3

<ma*****@gmail.comschreef in bericht
news:16**********************************@e23g2000 prf.googlegroups.com...
On Jan 16, 8:26 am, "C. (http://symcbean.blogspot.com/)"
>>
no - use move_uploaded_file() instead - RTFM

C.


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
copy and rename can be done in 1 step, as C suggested

http://nl2.php.net/move_uploaded_file

Jan 16 '08 #4
Thanks Guys I have it all working perfectly it seems!

Thanks again for your help very useful.
M
Jan 16 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by M Maloney | last post: by
25 posts views Thread by PyPK | last post: by
5 posts views Thread by Danny | last post: by
8 posts views Thread by pras.vaidya | last post: by
3 posts views Thread by knocte | last post: by
1 post views Thread by MorrganMail | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.