Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

referencing a file using php.

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
I am having a file copied into the same directory as this php script that I want to reference. - but the name of the file will vary etc.

Is there a way to reference the name of whatever file is in the same directory as the php script? so that I could email it, or move it, delete it, etc...

Jonathan
 
Is this the only other file that will ever exist in the directory? Or are there more?

You can;t reference a file if you don't know what its called. How are you moving the file?



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Here's what i'm doing:

using flash and php.

users in my flash app will upload a file by pressing a button - php code for moving the file into "files" directory is (let's call this "upload.php") :

Code:
//move the uploaded file
$file = "./files/".$_FILES['Filedata']['name'];
move_uploaded_file($_FILES['Filedata']['tmp_name'], $file);
chmod("./files/".$_FILES['Filedata']['name'], 0777);

(this works fine right now)
then user will fill out some textboxes with their information & will click submit button - I am going to transfer this information to a second php script - which I want to email me this information AS WELL AS add the file which was added with the previous php script in the "files" directory.

Am using phpmailer for email send - but am not sure how to reference that file in the "files" directory - so that I can attach it. - can you give me a bit of help?

Jonathan
 
2 ways:

1. Change its name when you move it using the File variable so you know what its called:

Code:
$file = "./files/name_of_file_after_beign_moved";[code]


or 2.

Use the $file variable to reference the file.  





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
but there will be two different php scripts - I can't use $file on my second script - becuase $file is given a value on the first script.

If I was going to rename - can you indicate what that would look like with my previous code - Thanks
 
How are you calling your next script?

You can save the $file into a session variable to carry it over to your other script, or added onto the url of your other script if you are calling it y a link or something.


but i guess just renaming it would be easier, as i said on the
previous post:

Code:
$file = "./files/name_of_file_you_want_it_to_have";

Like :


Code:
$file = "./files/myfile.ext";

Then you know exactly what its called and you can reference it.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I tried this and the file did not upload. Do I have this down correctly?

Code:
//move the uploaded file
$file = "./files/tester.ext";
move_uploaded_file($_FILES['Filedata']['tmp_name'], $file);
chmod("./files/".$_FILES['Filedata']['name'], 0777);
 
Try:

Code:
$file = "./files/tester.ext";
move_uploaded_file($_FILES['Filedata']['tmp_name'], $file);
chmod($file, 0777);

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top