Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/
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.
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-47588
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
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-47746
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]
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-47978
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
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48056
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.
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48061
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\" /]
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48279
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.
Link to comment
https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48412
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.