473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

error "supplied argument is not a valid stream resource" with fread()

bobzillaforever
I'm unable to get the file(s) in question to read with file_exists(), fread(), or probably any similar function. I've tried it with .txt, .flv, .pdf, .mov, .mp3, and .wmv. I've tried removing the following from my .htaccess file to no avail.

Expand|Select|Wrap|Line Numbers
  1. <FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
  2.   Order allow,deny
  3. </FilesMatch>
I've also tried adding the following to my .htaccess file, which was also unsuccessful.

Expand|Select|Wrap|Line Numbers
  1. AddType text/plain txt
I know that the files themselves are error-free and the correct URL is being delivered.

Here's the relevant code from my .php file:
[PHP]
$yy = date('Y', $created);
$mm = date('m', $created);
$dd = date('d', $created);
$yymmdd = $yy.$mm.$dd;
$flv = base_path() . 'files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd . '.flv';

if (file_exists($flv)) {
// my code
} else {
echo '<p>file ' . $flv . ' doesn\'t exist.</p>'; }
var_dump(file_exists($test));
echo '<br />';
fread($test, 8);[/PHP]
The last three lines are for testing purposes. And they're failing. :-)

Any help would be greatly appreciated. Thank you!

David

P.S. I'm using Drupal, and this is a node template. I hope that's not the problem, but just FYI.
Mar 16 '08 #1
7 2804
ronverdonk
4,258 Expert 4TB
What is this statement supposed to do?[php] $flv = base_path() . 'files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd . '.flv';[/php]base_path() is not a PHP function, so how can I check if you correctly build the file path/name?

And looking at the thread title, where is the fread() gone? Because that one is reported (by you) as giving the error.

file_exists() only returns a true or a false, so that is all var_dump will return.

Ronald
Mar 16 '08 #2
What is this statement supposed to do?[php] $flv = base_path() . 'files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd . '.flv';[/php]base_path() is not a PHP function, so how can I check if you correctly build the file path/name?
Apologies. base_path() is a Drupal function, returning (in this case) "/drupal-6/". I was trying to clean the irrelevant stuff from my code.
And looking at the thread title, where is the fread() gone? Because that one is reported (by you) as giving the error.
Same problem. I was trying to clean it up, and insodoing erased something important.
[PHP]$test = '/sundays/files/sundays/' . $yy . '/' . '/' $mm '/' . $yymmdd . '.txt';[/PHP]
Thank you, Ronald.

David
Mar 17 '08 #3
ronverdonk
4,258 Expert 4TB
You are welcome. See you next time.

Ronald
Mar 17 '08 #4
You are welcome. See you next time.

Ronald
Oops. To clarify, I haven't had any resolution yet. I will, however, continue working on this issue in the forums on Drupal's site, as I'm thinking that might be where my error starts. Thanks.
Mar 17 '08 #5
ronverdonk
4,258 Expert 4TB
I am sorry. I had the idea that you knew where the problem was located and that you were able to fix it. Anyway, see you again soon (maybe).

Ronald
Mar 17 '08 #6
Issue solved. It ended up having nothing to do with Drupal. I was unaware of the different ways a document root could be delivered. And unaware of how to use fread(), so my method of error-checking was faulty. My main issue was trying to get file_exists() to work.

I solved by changing:

[PHP]$fileCheck_url = base_path() . '/files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd;
//prints /drupal-6/files/sundays/2008/02/20080209[/PHP]To:

[PHP]$fileCheck_url = $_SERVER['DOCUMENT_ROOT'] . base_path() . '/files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd;
//prints C:/Apache/htdocs/drupal-6/files/sundays/2008/02/20080209[/PHP]That's working for me.

To get fread() to work, I used the following code:

[PHP] $fileCheck_url = $_SERVER['DOCUMENT_ROOT'] . base_path() . '/files/sundays/' . $yy . '/' . $mm . '/' . $yymmdd;
$fileCheck = array(
'flv' => $fileCheck_url . '.flv',
'wmv' => $fileCheck_url . '.wmv',
'mp3' => $fileCheck_url . '.mp3',
'txt' => $fileCheck_url . '.txt'
);

$handle = fopen($fileCheck['txt'], "r");
$contents = fread($handle, filesize($fileCheck['txt']));
fclose($handle);
print $contents;[/PHP]Thanks again!
Mar 18 '08 #7
ronverdonk
4,258 Expert 4TB
Glad you solved it in the end. See you soon.

Ronald
Mar 18 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Richard | last post by:
I am writing a script which accesses a DBM file using SDBM. The program works but throws out a warning of: - Argument "O_RDWR" isn't numeric in null operation I've included Fcntl but that...
2
by: Mr Flibble | last post by:
Hi All I've decided to put my stylesheets in a base64 .resource file for deployment and versioning reasons. I dont know if it's a great idea to do this but I couldn't think of another way of...
3
by: Martin | last post by:
Hi, I have an aspx page with two dropdownlist controls. I update the options in the second ddl based on selection made in the first. I do this with the ICallbackEventHandler interface, as per...
5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
7
by: bookon | last post by:
I was running into the System.Drawing.Image.FromStream "parameter is not valid" on some of the images I was retrieving from a blob column in Sql Server. I thought there were corrupt images as...
12
by: Pao | last post by:
Hi all For all NEW sites (virtual directories) that I create, I receive always the same error: (I translate so may be a little different) Impossible to visualize the XML page Impossible to...
4
by: robert | last post by:
On a server the binary (red hat) installed python2.4 and also a fresh compiled python2.5 spits "sem_post: Invalid argument". What is this and how can this solved? Robert ============== ...
0
by: gsauns | last post by:
I have a DetailsView which is inside of a FormView. I lifted this DetailsView straight off another one of my pages, where it was working beautifully. Now I get this endlessly frustrating error...
9
by: 200dogz | last post by:
Hi guys, I want to have a button which opens up a new window when pressed. <asp:Button ID="Button1" runat="server" Text="Open new window" /> ... Button1.Attributes.Add("OnClick",
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.