Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Bytea, $_FILE and querystring too long
Old 03-22-2008, 04:06 PM Bytea, $_FILE and querystring too long
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Hi all,

Im using php $_FILE with pg_escape_bytea to write files to a postgre db field of type bytea.

My actual php/sql is :

Code:
$q = query ("INSERT INTO section_files (sponsor_id, area_id, section_id, txt_title , upload_user_id ,
											upload_timestamp, bytes, mime_type, imagewidth, imageheight ) VALUES ( " . 
						p("sponsor_id") . "," .  $area_id . "," . p("section_id") . ",'" . $txt_title . "'," . 						 
						$upload_user_id . ",  now (), '" .	
						pg_escape_bytea (file_get_contents ($_FILES ['image'] ['tmp_name'])) . "', '" . 
						strtolower($mime_prefix) .   strtolower($phpMimeType) . "'," . $imagewidth . "," . $imageheight . ")");

My problem is that when the file is greater than 5mb, the converstion to bytea is greater than the 20mb PHP query length limit permitted and so fails!

My question is how do i work arround this? A suggestion has been to split the file into 1MB chunks and update use UPDATE however i am not that familiar with postgre and not sure how to do.

Alternatively, someone may have a different solution or suggestion.

Cheers

Steve
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 03-22-2008, 04:10 PM Re: Bytea, $_FILE and querystring too long
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
If possible, I would store the file in a directory somewhere and name it such that it cannot be overwirtten unintentionally. You can then just store the path to the file in your database.

If that is not possible, the only thing that comes to mind would be to, as you said, split the file into smaller files and then store those as multiple rows. You will need some indication that the file contained in each individual row is not complete.

Hope that helps.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-22-2008, 04:55 PM Re: Bytea, $_FILE and querystring too long
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
ok, thanks.

I would really like to store in the file system. Or i think i would. The files MUST be secure. Ive inherited this problem from someone else that has processed thefiles in this way. Have you any idea what security measures i can put in place to prevent direct file access. Some of the files uploaded will require a 2nd logon to view. I wont want people being able to access by url.

We have in place a .htaccess file but i am literally sat here pondering how we could use to secure these files.

Sorry to add, it's the HOW TO split files and write im stuck on.
__________________

Please login or register to view this content. Registration is FREE

Last edited by numbenator; 03-22-2008 at 05:00 PM..
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 03-24-2008, 03:11 AM Re: Bytea, $_FILE and querystring too long
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You can protect your files with apache basic auth, so it would ask for login and password when a protected file is requested. If you need to perform authorization within a script you will have to install some lightweight frontend webserver (I use nginx), read a lot of manuals and configure it accordingly. Or you may simply put your files outside of web accessible directory and send it with your script through fread(), but this is strongly not recommended because first you will have to reinvent a php webserver to run inside the binary webserver and second you will always have the non-zero probability of running out of memory on high volume of simultaneous requests.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Bytea, $_FILE and querystring too long
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 6.41971 seconds with 12 queries