Michdd Posted January 29, 2009 Share Posted January 29, 2009 This is just a simple question, something that I never bothered learning because I never needed to know it before... How do I save a file to my server using a php script? Link to comment https://forums.phpfreaks.com/topic/142913-simple-question/ Share on other sites More sharing options...
ober Posted January 29, 2009 Share Posted January 29, 2009 That's a very vague question. Are you creating the file? Is the file being uploaded? Is the file being passed to the server via a different process? Please be more specific. Link to comment https://forums.phpfreaks.com/topic/142913-simple-question/#findComment-749269 Share on other sites More sharing options...
Michdd Posted January 29, 2009 Author Share Posted January 29, 2009 That's a very vague question. Are you creating the file? Is the file being uploaded? Is the file being passed to the server via a different process? Please be more specific. Sorry, I mean say I have a variable $url = "http://site.com/picture.png"; How would I save that file? Basically saving a file from an outside source. Link to comment https://forums.phpfreaks.com/topic/142913-simple-question/#findComment-749272 Share on other sites More sharing options...
genericnumber1 Posted January 29, 2009 Share Posted January 29, 2009 There are a lot of ways, as stated by the previous poster, depending on what you're saving. As for simple plain text the simplest would be.. <?php $content = "test content"; file_put_contents('myfile.txt', $content); For less trivial text examples (eg. to save memory, since file_put_contents requires the full text to be loaded into memory) look into the fopen()/fwrite()/fclose() functions in the manual. ( http://us.php.net/manual/en/function.fopen.php ) Link to comment https://forums.phpfreaks.com/topic/142913-simple-question/#findComment-749276 Share on other sites More sharing options...
ober Posted January 29, 2009 Share Posted January 29, 2009 I would say it's going to fail about 50% of the time because people will block you via their servers. Otherwise, you can start reading here: http://br.php.net/manual/en/function.fread.php Link to comment https://forums.phpfreaks.com/topic/142913-simple-question/#findComment-749277 Share on other sites More sharing options...
Michdd Posted January 29, 2009 Author Share Posted January 29, 2009 Well I'm actually going to be taking 1 type of file from 1 server. Images, from a server that I know will allow it. So would file_put_contents() be the best way for this? (since it's only images) Link to comment https://forums.phpfreaks.com/topic/142913-simple-question/#findComment-749279 Share on other sites More sharing options...
ober Posted January 29, 2009 Share Posted January 29, 2009 file_put_contents would probably be your best bet then. Link to comment https://forums.phpfreaks.com/topic/142913-simple-question/#findComment-749289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.