2

I'd like to have my PHP script upload a file with a certain filename in a directory of my choosing. However, the catch is that I need it to exist there immediately upon upload so I can moniter it on my server. I don't want to use a PHP extension or something - this should be very easy to transfer to any PHP setup.

So basically: Is there a way to guarantee that, from the very beginning of the file upload process, the file has a certain name and location on the server?

2
  • 3
    Do you want to monitor it so you can display upload progress? So you can process the file as it's being uploaded? Some more background would be helpful, here. Commented May 15, 2010 at 2:03
  • I'm wanting to record upload progress, and also possibly do some processing - so both I guess! Commented May 15, 2010 at 3:54

5 Answers 5

3

Not that I'm aware of.

PHP will use the php.ini-defined tmp folder to store uploads until you copy them to their correct location with move_uploaded_file(). So it's very easy to know its location, but the file name is random and I don't think you can define it. If you're not going to have multiple concurrent uploads (for example if only you are going to upload files and you know you won't upload 2 files at the same time), you could check the most recent upload file in the tmp directory.

The common solution for monitoring uploads is apc.rfc1867

Sign up to request clarification or add additional context in comments.

2 Comments

+1. Yeah - I'm actually trying to find a workaround that doesn't need apc, as I'd like to use this for installations which don't have this. I really, really like the idea of finding the most recent upload file in the tmp directory. The only thing is - is there a way to have a second php script fire immediately once the upload starts to grab that most recent file's name?
Again, not that I'm aware of. The first line of php will be executed after everything is uploaded. You should call another page via AJAX when the form is submitted and to the processing there :)
1

I know of three options:

  1. RFC1867 (as mentioned by others) which allows you to poll upload progress using ajax
  2. Flash-based uploaders like SWFUpload which allow you to poll upload progress using JavaScript
  3. Create a PHP command line daemon listening on port 80 that accepts file uploads, and used shared memory (or some other mechanism) to communicate upload progress. Wish I could find the link, but I read a great article about a site that allowed users to upload their iTunes library XML file, and it was processed live by the server as it was being uploaded. Very cool, but obviously more involved than the previous options.

I have had decent luck with SWFUpload in the past.

Comments

0

I don't think you can configure the name, as it will be a random name in the temporary folder. You should be able to change the directory, but I can't seem to find the answer on Google (check out php.ini).

Comments

0

As far as I know, this isn't possible with PHP, as a file upload request submits the entire file to the system in one request. So there is no way for the PHP server to know what is happening until it receives the whole request.

Comments

0

There is not a way to monitor file upload progress using PHP only, as PHP does not dispatch progress events during the upload. This is possible to do using a Flash uploader even if Flash is uploading via a PHP script. Flash polls the temporary file on the server during the upload to dispatch progress events. Some of the javascript frameworks like YUI use a SWF to manage uploads. Check out YUI's Uploader widget.

http://developer.yahoo.com/yui/uploader/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.