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
read file can't open file
Old 06-04-2010, 03:41 PM read file can't open file
Extreme Talker

Posts: 173
Trades: 0
I have created a program to import a text file. I has been working fine until the source file got bigger then 3mb. Does fopen($file_name, "r") command have a limit to the size of the file that can be openned?



PHP Code:
// accepts file name
if (isset($_REQUEST['filename']))  $file_name $_REQUEST['filename'];
else         die(
'No filename provided...');
// Open file in read mode
$file = @fopen($file_name"r") or exit("Unable to open file!");
if (
$file) {
    
$sLBL fgets($file);
    
$project project($sLBL);  //Isolates project number from first row of text in file 
dgkindy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-04-2010, 05:19 PM Re: read file can't open file
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I don't know if fopen has size limit, but PHP does have limited allocated RAM limit and execution time limit. They can be changed within the script:

set_time_limit(300);
ini_set('memory_limit', '1024M');
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-07-2010, 06:22 AM Re: read file can't open file
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
fopen() does not have any limits on size of the file being opened. Most probably the problem is with your project() function. Please tell us exact errors and symptoms of "not working".
__________________

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!
 
Old 06-08-2010, 11:36 AM Re: read file can't open file
Extreme Talker

Posts: 173
Trades: 0
The error message that I am getting is

"Unable to open file!"

The file is 2.56 MB and is a text file data dump from SAP.

It has been working on smaller files fine. I reduced the file size of the data file by reducing the amount of data that is dumped from SAP so that a 764K file was created, and that works fine.

I have attached both the parsing function and a sample of the text file. It will not work on your system without modification as you do not have the db but you can have a look to see if you have any suggestions.
Attached Files
File Type: zip parse_md4c.zip (5.1 KB, 0 views)
File Type: zip gf half.zip (42.7 KB, 0 views)
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 06-08-2010, 01:46 PM Re: read file can't open file
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
okay, so first, add this to the beginning of the php script:
PHP Code:
error_level(E_ALL);
ini_set('display_errors'1); 
Re try your script, and tell us what exactly is the fopen() error, not the message you determined with an "or die()" condition.

Fopen() does not parse the file, it only gives back a pointer to iterate through the file. So it cannot be the size that causes the problem.
I'd rather think that the file was uploaded via ftp or via the network, and it's permissions are not low enough to allow the user that run the web server(usually nobody, or apache) to read the file.

Please ensure that your file is readable by everyone ("chmod 555 yourfile.txt" from a shell in the same directory as your file), it may be your problem.

For example, if a file is not found, fopen() should yield, given the following code:
PHP Code:
error_reporting(E_ALL);
$h=fopen('lalal','r'); 
Quote:
Warning: fopen(lalal): failed to open stream: No such file or directory in /home/tmo/2.php
If the file is not readable:
Quote:
Warning: fopen(lalal): failed to open stream: Permission denied in /home/tmo/2.php on line 3
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to read file can't open file
 

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 0.23419 seconds with 13 queries