Jump to content

File upload path


JRS

Recommended Posts

Hello,
I'm writing a mail script with attachment. I have a test mode, where a user can setup the mail and do mass mailing. One of the setup is for the user to select a file attach to the email and do test mailing. If this ok, do the mass mailing.

I would like to get the full path and filename of the attachment. However, the $_FILES global variable will only provide the filename and temporary path - appears to be in Windows\temp directory.

The real path is c:\email\testfile.txt
I can only get name: testfile.txt and path\tempfile would be windows\temp\php5.txt

So after the test mailing - user has to browse for the file attachment again - I'm not able to set the value because I do not have the path available to me. Is this a security issue? Is there a way for me to get the real path of the file attachment?

Thanks in advance
JRS
Link to comment
Share on other sites

Remember, PHP runs on the server which may or may not be the same machine the user is on. Why would you want to know the original location of the attachment. The recipient doesn't care. He just wants the contents of the file. The path you mentioned would only be true if you are running the server on Windows and took the default path for the /tmp directory. And the sender already knows where the original was.

Ken
Link to comment
Share on other sites

[!--quoteo(post=368274:date=Apr 25 2006, 12:05 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 25 2006, 12:05 AM) [snapback]368274[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Remember, PHP runs on the server which may or may not be the same machine the user is on. Why would you want to know the original location of the attachment. The recipient doesn't care. He just wants the contents of the file. The path you mentioned would only be true if you are running the server on Windows and took the default path for the /tmp directory. And the sender already knows where the original was.
Ken
[/quote]

Ken,
Thanks for the reply, the reason I want the path is to make the life of the sender easier. Now, after the sender sends the test email - the file attachment input window is reset to blank. So if the sender wants to send the email to all the people on his/her list - the sender has to browse to the file again to attach it. However, if I knew where it was - then I can set the value of the <input type=file ...> field.

My concern is person would send the test email - find it ok, decides ok let do the mass mailing and forget to attach the file - since they already did it once. (Plus I am also able to repopulate all other fields on the form - except for the file attachment)

Thanks
JRS
Link to comment
Share on other sites

The only way you can save the path on the client side is with Javascript,, I also think that Javascript can prefill the browse box. I know PHP can't.

What you may have to do is to use AJAX to invoke a PHP routine, passing it the client side path to store in a session variable, then the next time you put up the form, your PHP script would get the value out of the session variable and write the Javascript code that would pre-fill the field.

I don't know whether this will work, since I just thought of it and haven't had time to write any code, let alone test it.

Ken
Link to comment
Share on other sites

[!--quoteo(post=368283:date=Apr 25 2006, 12:56 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 25 2006, 12:56 AM) [snapback]368283[/snapback][/div][div class=\'quotemain\'][!--quotec--]
The only way you can save the path on the client side is with Javascript,, I also think that Javascript can prefill the browse box. I know PHP can't.

What you may have to do is to use AJAX to invoke a PHP routine, passing it the client side path to store in a session variable, then the next time you put up the form, your PHP script would get the value out of the session variable and write the Javascript code that would pre-fill the field.

I don't know whether this will work, since I just thought of it and haven't had time to write any code, let alone test it.

Ken
[/quote]
Ken,
Thanks - I will give it a shot.
JRS
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.