Discussion:
Query regarding temporarily-uploaded files
Ajay Garg
2013-07-10 17:21:04 UTC
Permalink
Hi all.

I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.

Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")

Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)



Now, I am facing the following use-case ::

1)
User 1 starts uploading a large file, say "big_file.avi".

2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".


In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?

( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).


Any way the issue may be solved?

I will be grateful for any pointers :)



Regards,
Ajay
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-07-10 17:32:43 UTC
Permalink
Post by Ajay Garg
Hi all.
I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.
Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")
Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)
1)
User 1 starts uploading a large file, say "big_file.avi".
2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".
In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?
( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).
Any way the issue may be solved?
I will be grateful for any pointers :)
Regards,
Ajay
The problem is not of PHP's making. It is something that you have to
program around. Is the user determining the filename to be used? If
so, then you need to check for that name before doing you "move". If
it's a duple, then create a temporary name in your final place, hide it
in the user's page and send it back to him with a message to change his
name.

If the user is NOT determining the name, then your normal process would
be to pick an unused name I presume and send That back to the user
anyway, so problem never happens.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Matijn Woudt
2013-07-10 17:39:37 UTC
Permalink
Post by Ajay Garg
Hi all.
I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.
Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")
Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)
1)
User 1 starts uploading a large file, say "big_file.avi".
2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".
In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?
( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).
Any way the issue may be solved?
I will be grateful for any pointers :)
Regards,
Ajay
Hi,

This is not possible with PHP, PHP will not know about the file until the
upload is completed. You can use HTML5 or flash(not recommended) for an
alternative way of uploading, and then you can check the file name in
advance.

- Matijn
Ajay Garg
2013-07-10 18:15:42 UTC
Permalink
Thanks Jim and Matijn for the quick replies.
I will try to have a workaround.
Post by Matijn Woudt
Post by Ajay Garg
Hi all.
I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.
Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")
Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)
1)
User 1 starts uploading a large file, say "big_file.avi".
2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".
In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?
( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).
Any way the issue may be solved?
I will be grateful for any pointers :)
Regards,
Ajay
Hi,
This is not possible with PHP, PHP will not know about the file until the
upload is completed. You can use HTML5 or flash(not recommended) for an
alternative way of uploading, and then you can check the file name in
advance.
- Matijn
--
Regards,
Ajay
Jim Giner
2013-07-10 19:27:01 UTC
Permalink
Post by Ajay Garg
Thanks Jim and Matijn for the quick replies.
I will try to have a workaround.
Post by Matijn Woudt
Post by Ajay Garg
Hi all.
I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.
Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")
Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)
1)
User 1 starts uploading a large file, say "big_file.avi".
2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".
In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?
( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).
Any way the issue may be solved?
I will be grateful for any pointers :)
Regards,
Ajay
Hi,
This is not possible with PHP, PHP will not know about the file until the
upload is completed. You can use HTML5 or flash(not recommended) for an
alternative way of uploading, and then you can check the file name in
advance.
- Matijn
As Matijn said, you don't know the name until your php processes the
file that has been uploaded alreaday. But my solution will work for you
- you just have to save it under the temp name until the user responds
to your message and request for a new title. You may have to run a
periodic script to clean up any files with your temp names that the user
declined to re-name for you. I'd make up a temp name with some special
prefix so that you can find and delete them.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Anthony Wlodarski
2013-07-10 19:29:12 UTC
Permalink
Is there anything that would prevent you from somehow uniquely knowing who
the user is uploading the file. For example you mentioned "client'. If you
know
who the client is you can append that to the filename or prepend it, for the
destination string (second parameter to the function call). That way it is
unique
to that client.

-Anthony
Post by Ajay Garg
Thanks Jim and Matijn for the quick replies.
I will try to have a workaround.
Post by Matijn Woudt
Post by Ajay Garg
Hi all.
I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.
Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")
Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)
1)
User 1 starts uploading a large file, say "big_file.avi".
2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".
In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?
( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).
Any way the issue may be solved?
I will be grateful for any pointers :)
Regards,
Ajay
Hi,
This is not possible with PHP, PHP will not know about the file until the
upload is completed. You can use HTML5 or flash(not recommended) for an
alternative way of uploading, and then you can check the file name in
advance.
- Matijn
--
Regards,
Ajay
--
Anthony W.
***@gmail.com
Ajay Garg
2013-07-10 19:37:29 UTC
Permalink
Thanks Jim and Anthony.

Jim,
You are right, your solution is doable.

But one thing I am a little skeptical about, is what would be the
percentage of the people willing to suggest a new name "immediately",
versus the percentage of people who would like to cancel the current
upload, and come back "later" after walking and coming up with a new name.

Anyhow, let me sleep over it :)


Anthony,
your solution is really a special case of Jim's solution :)



Thanks guys for the quick replies; I am obliged, really.
Post by Anthony Wlodarski
Is there anything that would prevent you from somehow uniquely knowing who
the user is uploading the file. For example you mentioned "client'. If
you know
who the client is you can append that to the filename or prepend it, for the
destination string (second parameter to the function call). That way it
is unique
to that client.
-Anthony
Post by Ajay Garg
Thanks Jim and Matijn for the quick replies.
I will try to have a workaround.
Post by Matijn Woudt
Post by Ajay Garg
Hi all.
I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.
Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")
Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)
1)
User 1 starts uploading a large file, say "big_file.avi".
2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".
In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?
( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).
Any way the issue may be solved?
I will be grateful for any pointers :)
Regards,
Ajay
Hi,
This is not possible with PHP, PHP will not know about the file until
the
Post by Matijn Woudt
upload is completed. You can use HTML5 or flash(not recommended) for an
alternative way of uploading, and then you can check the file name in
advance.
- Matijn
--
Regards,
Ajay
--
Anthony W.
--
Regards,
Ajay
Jim Giner
2013-07-10 19:47:24 UTC
Permalink
Post by Ajay Garg
Thanks Jim and Anthony.
Jim,
You are right, your solution is doable.
But one thing I am a little skeptical about, is what would be the
percentage of the people willing to suggest a new name "immediately",
versus the percentage of people who would like to cancel the current
upload, and come back "later" after walking and coming up with a new name.
Anyhow, let me sleep over it :)
Anthony,
your solution is really a special case of Jim's solution :)
Thanks guys for the quick replies; I am obliged, really.
Post by Anthony Wlodarski
Is there anything that would prevent you from somehow uniquely knowing who
the user is uploading the file. For example you mentioned "client'. If
you know
who the client is you can append that to the filename or prepend it, for the
destination string (second parameter to the function call). That way it
is unique
to that client.
-Anthony
Post by Ajay Garg
Thanks Jim and Matijn for the quick replies.
I will try to have a workaround.
Post by Matijn Woudt
Post by Ajay Garg
Hi all.
I have a requirement, wherein I need to allow vanilla uploads of files
to a HTTPD server.
Any client can upload any number of files (one at a time).
Also, there is just one directory, where the files get stored
"finally" (that is, after being copied from the temporary location,
via "move_uploaded_file")
Also, I have been able to get the simple file uploading running via
PHP, by picking up one of the numerous "Hello World" examples
available :)
1)
User 1 starts uploading a large file, say "big_file.avi".
2)
Meanwhile, user 2 also starts uploading a (different) file, but with
the same name "big_file.avi".
In an ideal scenario, user 2 should be prompted with a message, that a
file of the same name is already being uploaded by someone else
somewhere.
Is there a way to do this?
( Note that, had the user 2 started uploading AFTER user 1 had
finished with the upload, we could probably modify the PHP-script at
the sever-side, to let user-2 know that a file of the same name
already exits. But I am failing to find a solution, when the user 2
starts the upload WHILE the large file of user 1 is in the process of
completing uploading).
Any way the issue may be solved?
I will be grateful for any pointers :)
Regards,
Ajay
Hi,
This is not possible with PHP, PHP will not know about the file until
the
Post by Matijn Woudt
upload is completed. You can use HTML5 or flash(not recommended) for an
alternative way of uploading, and then you can check the file name in
advance.
- Matijn
--
Regards,
Ajay
--
Anthony W.
That's why I said you would have to do a cleanup periodically. People
who walk away could lose their session perhaps and the page wiht the
hidden temp name buried in it, so they would have to do their upload
from the beginning again. If they didn't lose their session and
therefore that screen, then they could still respond and things would
flow smoothly.

so - who is scanning these files for viruses and what not? It's one
thing to host them but if you are going to let users view them on their
clients you could be spreading things.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Bastien
2013-07-10 20:25:26 UTC
Permalink
Bastien Koert
Post by Anthony Wlodarski
Is there anything that would prevent you from somehow uniquely knowing who
the user is uploading the file. For example you mentioned "client'. If you
know
who the client is you can append that to the filename or prepend it, for the
destination string (second parameter to the function call). That way it is
unique
to that client.
-Anthony
Another option is that you name the files yourself. Numerically for example and then just switch it back to the uploaded file name when either displaying it or sending it back to the user.

You should also place all files outside the web root so it's harder to execute bad files. And prolly filter for files types. Allow only images ( png jpg gif ) for example

Bastien
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...