Jump to content

Archived

This topic is now archived and is closed to further replies.

Raconteur

fopen on XP fails

Recommended Posts

Hi all,

I am trying to do a simple fopen

[code]fopen('c:\temp\pic.gif', 'r')[/code]

but it keeps failing with

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: fopen(c:/temp/pic.gif): failed to open stream: No such file or directory in /home/find6/public_html/ftp.class.php on line 258[/quote]

Is there some well-known but poorly documented trick to making fopen work? I have scoured PHP.NET and cannot find anything that seems to help.

Any assistance GREATLY appreciated!

Cheers,

Chris

Share this post


Link to post
Share on other sites
Are you absolutely sure the file exists?

Also, can you post up the rest of that block of code?

Share this post


Link to post
Share on other sites
From looking at what the error is returning it looks like your site is running on a non windows box which is running *nix/mac and you're using fopen to fetch a file from your hard drive. This is not possible. PHP runs on the server and cant access a clients computer to fetch data.

Share this post


Link to post
Share on other sites
Hi there,

Thanks for the responses.

SA, yes, the file definitely exists.

wildteen88, you are correct, the script is running on a server running Unix, and I am trying to access a file on my local machine. But if that is not possible, how can you FTP something? Wouldn't make sense if you couldn't upload from a local source... Am I missing something here?

Cheers,

Chris

Share this post


Link to post
Share on other sites
You need to upload the file instead, by creating a html form and PHP code to move the ffile to the desired location, look at this tutorial on doing so:
[a href=\"http://www.developerfusion.co.uk/show/2892/\" target=\"_blank\"]http://www.developerfusion.co.uk/show/2892/[/a]

Share this post


Link to post
Share on other sites
Ahhh... now things are becoming clearer.

That bit of upload code is exactly my problem. I have a CMS that allows users to upload pics for use on the site, however, by using that mechanism of uploading, the images are owned by the PHP process owner "nobody". That means that we cannot do anything with the files once they are up there (can't move them, delete them, etc.).

So, I thought if I FTP'd them up, they would be owned by the FTP user. But the FTP base is doing the same thing?

I guess I will have to resort to Perl, which from what I understand, will run as the user.

Thanks a ton!

Chris

Share this post


Link to post
Share on other sites
If you want to use the FTP protocol PHP has inbuilt ftp functions, [a href=\"http://uk.php.net/manual/en/ref.ftp.php\" target=\"_blank\"]click here[/a] for more imformation. Ignore the installation and requirements bit and look at the example, its about half way down the page.

Share this post


Link to post
Share on other sites
Problem is it still uploads the file under the PHP script which marks it owned by "nobody". Perl (CGI in general) run under a user account, rather than "nobody", so the Perl solution is working... I just need to integrate it into my PHP.

Any suggestions there? [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]

Share this post


Link to post
Share on other sites
try somethin like this i have xp and this code works for me
[code]
$filename="c:\temp\pic.gif";

   if (!$handle = fopen($filename, 'r')) {
         echo "Cannot open file ($filename)";
         exit;
   }

[/code]



Share this post


Link to post
Share on other sites
Raconteur I dont get what you mean by it marks it owned by nobody. Why does it need to be marked as some user? I'm a little confused at the momemnt, prehaps its because I am a newb at *unix based systems.

Prehaps you need to add a line called a [i]shebang line[/i] (I think thats waht it is called):
[code]#!/usr/bin/php
<?php

// your code here

?>[/code]
If not I'm not sure, I would expect there is some way to do what you want to do.

Share this post


Link to post
Share on other sites
Surely if it is owned by the php user 'nobody', it wouldn't matter as you would be controlling it with php for the rest of your scripts anyway? Or is that not the case? I'm a little confused here too!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.