arkum Posted January 16, 2007 Share Posted January 16, 2007 Hello, I'm pretty crap with php, and I think the answer to this must be very simple...I've got a bit of code that works fine. Originally the value asigned to $myfilePath was passed in like so:[code]$myFilePath=$_POST["pathToFile"];[/code]And this worked fine. But now I have decided I want it hardcoded so I've tried this:[code]$myFilePath="myfolder/";[/code]But this causes the script to fail.Here is the script with the rellevent bit in red:[code]<?php$tField=$_POST["myTextField"];[color=red]$myFileName= $_POST["myFileName"];$content=$_POST["myContent"];$myFilePath="myFolder/"$myFileFull = $myFilePath.$myFileName;[/color]$targetFile;$msg;if(file_exists($myFileFull)) { $msg = 'Exists'; if(is_writable($myFileFull)) { $msg .= '_isWritable'; if (!$targetFile = fopen($myFileFull, 'w+')){ $msg .= "_can't be opened"; }else{ if(fwrite($targetFile, $content) === FALSE){ $msg .= "_can't be written"; }else{ $msg .= '_isWritten'; } } }else{ $msg .= '_is not writable'; }}else{ $msg = "Doesn't Exist"; $timestamp = strtotime("now"); $myFileName = 'body_'. $timestamp; $myFileFull = $myFilePath.$myFileName; if (!$targetFile = fopen($myFileFull, 'w')){ $msg .= "_($myFileName)_Can't create NEW file"; }else{ if(fwrite($targetFile, $content) === FALSE){ $msg .= "_($myFileName)_Can't write to NEW file"; }else{ $msg .= '_($myFileName)_is CREATED and isWritten'; } } }echo "&msg=$msg&myFile=$myFileName&content=$content&myTextField=$tField";?> [/code]Thanks Link to comment https://forums.phpfreaks.com/topic/34409-probably-an-idiot/ Share on other sites More sharing options...
Accurax Posted January 16, 2007 Share Posted January 16, 2007 I have problems likr this all the time... and normally its just down to the path that im using .... are you sure you have it correct? Link to comment https://forums.phpfreaks.com/topic/34409-probably-an-idiot/#findComment-161962 Share on other sites More sharing options...
arkum Posted January 16, 2007 Author Share Posted January 16, 2007 Hi Accurax,Yeah I'm sure. Just copy/pasted it. Just out of interest, is the rest of my code looking ok. It works, but would like to know if there is anything I'm doing that should be done differently.Thanks Link to comment https://forums.phpfreaks.com/topic/34409-probably-an-idiot/#findComment-161964 Share on other sites More sharing options...
arkum Posted January 16, 2007 Author Share Posted January 16, 2007 Ok,so if I use:[code]$myFileFull = "body_text/".$myFileName;[/code]it works fine, but if I use:$myFilePath = "body_text/";$myFileFull = $myFilePath.$myFileName;It fails. This makes no sense to me. Link to comment https://forums.phpfreaks.com/topic/34409-probably-an-idiot/#findComment-161971 Share on other sites More sharing options...
Accurax Posted January 16, 2007 Share Posted January 16, 2007 If your not going to change the actual path... you may as well leave it hardcoded... no point having a variable that you dont use imo Link to comment https://forums.phpfreaks.com/topic/34409-probably-an-idiot/#findComment-161979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.