daveh33 Posted October 21, 2007 Share Posted October 21, 2007 The code I am using is: - $title = $_POST['title']; $random = rand(+1,1000000); $filename = '/promotions/$title_$random.php'; $fh = fopen("$filename", "w"); if($fh==false) die("unable to create file"); I get the error Warning: fopen(/promotions/$title_$random.php): failed to open stream: No such file or directory in insertnew.php on line 13 unable to create file I have set the permissions to 777 - why would I get this error? Or should I be using a different code?? Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/ Share on other sites More sharing options...
only one Posted October 21, 2007 Share Posted October 21, 2007 Im not too sure if you can create files, check the fwrite() function. Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/#findComment-374956 Share on other sites More sharing options...
daveh33 Posted October 21, 2007 Author Share Posted October 21, 2007 I was sure it was possible to create a file... am I wrong?? Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/#findComment-374958 Share on other sites More sharing options...
derwert Posted October 21, 2007 Share Posted October 21, 2007 Look at the location you are trying to create the file: $filename = '/promotions/$title_$random.php'; that is an absolute path; I believe you're trying to create the file in the wrong location. Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/#findComment-374971 Share on other sites More sharing options...
daveh33 Posted October 21, 2007 Author Share Posted October 21, 2007 So what I need the full url? Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/#findComment-374977 Share on other sites More sharing options...
lewis987 Posted October 21, 2007 Share Posted October 21, 2007 $title = $_POST['title']; $random = rand(+1,1000000); $filename = '/promotions/$title_$random.php'; shouldbe: $title = $_POST['title']; $random = rand(1,1000000); $filename = '/promotions/'.$title.'_'.$random.'.php'; Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/#findComment-374979 Share on other sites More sharing options...
derwert Posted October 21, 2007 Share Posted October 21, 2007 upload this script into your promotions directory and bring it up in your browser, it will give you the full path to that locations. <?php echo getcwd(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/#findComment-374993 Share on other sites More sharing options...
daveh33 Posted October 21, 2007 Author Share Posted October 21, 2007 Many thanks that works Quote Link to comment https://forums.phpfreaks.com/topic/74228-solved-error-trying-to-create-file-in-php/#findComment-375006 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.