Raconteur Posted June 20, 2006 Share Posted June 20, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/ Share on other sites More sharing options...
zq29 Posted June 20, 2006 Share Posted June 20, 2006 Are you absolutely sure the file exists?Also, can you post up the rest of that block of code? Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-47565 Share on other sites More sharing options...
wildteen88 Posted June 20, 2006 Share Posted June 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-47588 Share on other sites More sharing options...
Raconteur Posted June 20, 2006 Author Share Posted June 20, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-47746 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-47978 Share on other sites More sharing options...
Raconteur Posted June 21, 2006 Author Share Posted June 21, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48056 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48061 Share on other sites More sharing options...
Raconteur Posted June 21, 2006 Author Share Posted June 21, 2006 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\" /] Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48279 Share on other sites More sharing options...
shortj75 Posted June 22, 2006 Share Posted June 22, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48404 Share on other sites More sharing options...
wildteen88 Posted June 22, 2006 Share Posted June 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48412 Share on other sites More sharing options...
zq29 Posted June 22, 2006 Share Posted June 22, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/12442-fopen-on-xp-fails/#findComment-48417 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.