473,769 Members | 6,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

bobzillaforever
4 New Member
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($f lv)) {
// my code
} else {
echo '<p>file ' . $flv . ' doesn\'t exist.</p>'; }
var_dump(file_e xists($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 2819
ronverdonk
4,258 Recognized Expert Specialist
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
bobzillaforever
4 New Member
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 Recognized Expert Specialist
You are welcome. See you next time.

Ronald
Mar 17 '08 #4
bobzillaforever
4 New Member
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 Recognized Expert Specialist
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
bobzillaforever
4 New Member
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($fileChec k['txt'], "r");
$contents = fread($handle, filesize($fileC heck['txt']));
fclose($handle) ;
print $contents;[/PHP]Thanks again!
Mar 18 '08 #7
ronverdonk
4,258 Recognized Expert Specialist
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
1859
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 doesn't solve the problem. Does anyone why this is happening? Thanks
2
4299
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 doing this other than making them available via www which may or may not be accessible (so this is a no go). Bear with me because I've only been using C# for one day so far (today is day 2! wohoo). // begin code snippet
3
7425
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 "Implementing Client Callbacks Without Postbacks in ASP.NET Web Pages" (http://msdn2.microsoft.com/en-us/library/ms178208.aspx) This works.
5
14134
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 my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
7
4822
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 almost all worked (all are gifs), and only a few broke when this line ran: Image img = Image.FromStream(ms); here is the original code: b = (byte)dt.Rows.ItemArray; //b.ToString() ms = new MemoryStream(); ms.Write(b, 0, b.Length);
12
2337
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 visualize the XML input through the XSL sheet. Correct the error, then click on Update, or try another time.
4
3380
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 ============== server # python2.4 sem_post: Invalid argument
0
1534
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 message whenever I try to go into Edit mode: Specified argument was out of the range of valid values. Parameter name: index The DetailsView is actually inside an UpdatePanel, which is inside an Ajax Accordion, which is inside the FormView. Could...
9
4564
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
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.