Cam
Cam

Reputation: 15234

PHP upload filename

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?

Upvotes: 2

Views: 353

Answers (5)

wpjmurray
wpjmurray

Reputation: 8141

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/

Upvotes: 0

user7675
user7675

Reputation:

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.

Upvotes: 1

Mitch Dempsey
Mitch Dempsey

Reputation: 39889

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.

Upvotes: 0

MartinodF
MartinodF

Reputation: 8254

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

Upvotes: 3

alex
alex

Reputation: 490233

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).

Upvotes: 0

Related Questions