Forums

PHP

This topic is locked

php upload file

Posted 15 Oct 2001 22:52:55
1
has voted
15 Oct 2001 22:52:55 fabio tonti posted:
Hi,
I used either the php upload file (with the "increase max upload file" too) and a simple script also, to upload mp3 files on my freebsd mp3 juke box.

The problem is that mp3 are large, and the system cannot upload the file. If I try whit a smaller file is all right.

I changed custom configuration in php.ini and php3.ini (max_upload ....) as mentioned in a another faq, but the problem remain.

My box is a Freebsd 4.3 with 256Mb ram, php4 and mysql.

Who can help me?

Fabio

Replies

Replied 15 Oct 2001 23:30:55
15 Oct 2001 23:30:55 Bruno Mairlot replied:
Could you tell us more about exactly what doesn't work ?

Is the file present in the tmp directory ?

What is the value of the supposed file location ?

Does PHP generate an error message ?

--- Better to die trying, than never try at all ---
Replied 16 Oct 2001 00:39:11
16 Oct 2001 00:39:11 Tim Green replied:
The problem is that it gets progressively harder for file uploads to work the larger the file size.

These kinds of behaviours are best suited to documents/images/sound or movie clips. If you are wanting to upload larger files you run into a few problems.

First of all is the amount of memory that PHP will consume. The larger the file, the more data PHP has to store in the servers memory. Basically when the upload begins the file is sent byte by byte into the server's RAM. When the file is completely uploaded the contents of RAM are dumped to the temporary directory, and the upload script copies the file from there to your desired location. Unfortunately it has to be this way as otherwise every upload or partial upload will leave file fragments in your server's file system which will soon consume more disk space than needed.

That is obstacle one.

Obstacle two, is that PHP will only execute a script for a certain length of time. If the script hasn't finished by this time, then the execution bombs out with an error stating that a 'Timeout' was achieved. Again, PHP has to function this way as it is multi-threaded. If it did not work this way then potentially even just 2 visitors to your site could cripple it. You can manually adjust this time in your PHP.ini, though you must bear in mind that the longer you allow scripts to run the higher the probability is of the server going down if you have a high traffic site.

Your final obstacle is security. If you are allowing multiple users the ability to upload large files to your webserver then your site won't work for very long. Take this example:-

30 visitors decide to upload a single MP3 file of size 8Mb. This one action by 30 visitors would immediately consume a mimimum of 240Mb of RAM, add on top of that the memory requirement for processing that much data and you could safely double it. Now writing that data out to a tempfile will consume yet another 240Mb RAM while the system caches out to disk and dumps the contents. That's 720Mb of RAM in concurrent useage. Add to that your other visitors, and you'll soon see that it isn't a great idea.

Now, there is a far better option, if you absolutely MUST work with large files. PHP can upload files in more than one way. You can also use PHP to FTP the files to a given location. There are a number of resources that will help with this, but no matter what you decide on you are looking at a totally hand-coded solution.

Try phpclasses.upperdesign.com for a myriad of PHP classes and in one of the categories somewhere, I seem to recall a FTP class.

Hope this helps.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 16 Oct 2001 22:37:37
16 Oct 2001 22:37:37 fabio tonti replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Could you tell us more about exactly what doesn't work ?

Is the file present in the tmp directory ?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
No, I look for them, by there isn't

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>

What is the value of the supposed file location ?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
/usr/local/shoutcast/content

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>

Does PHP generate an error message ?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

No, no message, only that the size is zero.
Note that if I use a simple script php return the right file name to me, but it does not copy it in the location I need.

Replied 17 Oct 2001 07:27:51
17 Oct 2001 07:27:51 Stephen Cox replied:
check out php.resourceindex.com/ for a ton of PHP scripts. I remember seeing several File Upload scripts which you can easily edit to suit your needs (I did just that).

Stephen Cox
web.net geek for nonprofits and political campaigns.
Replied 18 Oct 2001 01:47:20
18 Oct 2001 01:47:20 Tim Green replied:
This looks to me like a permissions issue.

First of all check that you have set the upload_tmp directory in your PHP.ini, then ensure that you give that directory sufficient permissions so that your WebServer can actually copy files there. The same must also be true of the /usr/local/shoutcast/content directory, as it sits outside of your web root.

In 99% of these cases it is a permissions issue, so you must ensure that you get this right.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Reply to this topic