Jump to content


Photo

fopen on XP fails


  • Please log in to reply
10 replies to this topic

#1 Raconteur

Raconteur
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 20 June 2006 - 06:03 AM

Hi all,

I am trying to do a simple fopen

fopen('c:\temp\pic.gif', 'r')


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

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 20 June 2006 - 08:28 AM

Are you absolutely sure the file exists?

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

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 June 2006 - 10:01 AM

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.

#4 Raconteur

Raconteur
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 20 June 2006 - 05:44 PM

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

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 June 2006 - 11:09 AM

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]

#6 Raconteur

Raconteur
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 June 2006 - 02:50 PM

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

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 June 2006 - 02:57 PM

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.


#8 Raconteur

Raconteur
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 June 2006 - 11:44 PM

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\" /]

#9 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 22 June 2006 - 08:09 AM

try somethin like this i have xp and this code works for me
$filename="c:\temp\pic.gif";

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





The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 June 2006 - 09:40 AM

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 shebang line (I think thats waht it is called):
#!/usr/bin/php
<?php

// your code here

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

#11 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 22 June 2006 - 10:10 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users