Jump to content

how tmp_name generates?


memphis.rayy

Recommended Posts

Hi guys,

I've been doing all kinds of things for about 3 weeks to find out how on earth does php generate tmp_name for $_FILE?

I have many questions about it...

For example, Is it possible to change tmp_name before uploading files?

If not, is it possible to generate or calculate tmp_name before reaching $_FILE['<your file field>']['tmp_name'].

 

I hope someone can answer my questions.

 

Thanks

Memphis

Link to comment
Share on other sites

tmp_name is just a random name that is assigned to a temporary file. But the file is deleted after the script is over. So I just do something like $tmp_name = $_FILES['blah']['tmp_name'] that way I can continue to use the tmp_name as needed for the current script. There's no need to change tmp name bc you can always reference it during the script.

 

Just remember though, you don't care what the value of tmp_name is because once you move to a different page, the file that tmp_name points to is deleted.

Link to comment
Share on other sites

Hello dannyb785,

Thanks for your replay.

 

My problem is, I want to upload a file to server and get the size of that file while is being uplaoded. I know I have to patch my PHP, use PECL, use perl and balah blah blah....

The thing is you can get the size of that file while is being uploaded, if you know the tmp_name before uploading the file.

You have to know that, once your script gets to $FILE, it starts to get the file and it won't give tmp_name value until the whole file is uploaded. (you can write a PHP script to check the temp folder and return the name of tmp_name but imagine that multiple users are sending their files to your server. How would you know which file is belong to who...?????? ??? ??? ??? ???)

 

I also change the tmp directory for every single user, it works actually but I want to know if there is another way of doing this. Please don't tell me I have to patch it. I can not do it because of my server. So Does any one know how to set tmp_name or get the value of tmp_name before uploading the file?

 

I hope I've made myself clear as a Cristal.

 

So I'm asking again, Is it possible to generate tmp_name before uploading? can we change it?

 

Thanks,

Memphis

Link to comment
Share on other sites

the short answer: no.

 

 

tmp_name is just temporary! It's a random name that way it's unique so that if 10,000 other files were uploaded at the same time, they'd all have different tmp_names. The tmp_name fiole only exists during the script, and it's the file in its entirety, just temporary. So if you did you form, added the file, and the processing page didn't do anything with tmp_name, once the page was complete, you wouldn't have a single byte more of disk space since it's deleted. So the tmp_name file IS the uploaded file, so trying to get a tmp_name before the file is uploaded doesn't make any sense.

 

What I would like to know is, what are you trying to do that you can't(or think you can't) currently?

Link to comment
Share on other sites

Hi,

Have you seen progress bar? I don't want to make one, because I won't be able to get the total size of the file before the file is completely uploaded. I want to make some progress number, like what's your current upload speed and how many bytes have you sent so far. I look all over the net and it brings one thing. You have to ether patch php or use perl in order to get file handler.

 

Right now because of my server I can not access to PECL libraries. they don't want to install it on their servers. So basically I have to do it without it. The only thing that I wanted to know was, Is it possible to make tmp_name or get it before uploading. that's all.

 

memphis

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

Did either memphis.rayy or ronald29x ever get a solution to this?

 

I've created a nifty multiple-file upload gizmo that shows percent completion as the various files upload.

 

However, I just realized that it won't work if multiple users do it at the same time.

 

I would like to choose a tmp_name, but I would settle with having a different tmp dir for each session.

 

Thx. 

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.