lindm Posted December 15, 2007 Share Posted December 15, 2007 Alright my problem. I have a html (form.html) page in a subdirectory of my site which lets the user submit a chosen file to a php file (writeform.php) in another directory for processing. Receive the following error: Warning: file(file.txt) [function.file]: failed to open stream: No such file or directory in /Library/WebServer/Documents/htdocs/phptest2/script/writeform.php on line 131 Code part of form.html <form action="../../script/writeform.php" method="post" enctype="multipart/form-data" name="form" id="form"> <input name="userfile" id="userfile" type="file" class="px10" size="6" /><INPUT name="SIE" TYPE="SUBMIT" class="px10" VALUE="Import"/> </form> Code part of writeform.php (includes row where error occurs) $contents = file($_FILES['userfile']['name']); foreach($contents as $line_value) {CONTINUED CODE... When I change $_FILES['userfile']['name'] to the aboslute path of a file it uses the file as expected, but when submitted from form.html the error occurs...does writeform.php not find the file?? What to do? Quote Link to comment https://forums.phpfreaks.com/topic/81845-solved-file-upload-problem/ Share on other sites More sharing options...
papaface Posted December 15, 2007 Share Posted December 15, 2007 Provide more code, I dont think you've given enough to fix the problem. Quote Link to comment https://forums.phpfreaks.com/topic/81845-solved-file-upload-problem/#findComment-415796 Share on other sites More sharing options...
lindm Posted December 15, 2007 Author Share Posted December 15, 2007 Alright: the function in writeform.php to extract certain data from the submitted file in form.html: function calculate_range($cat, $bool, $range_min, $range_max) { if(isset($_POST["SIE"])){ $contents = file($_FILES['userfile']['name']); foreach($contents as $line_value) { list($_cat, $_bool, $_id, $num) = explode("\t", $line_value); $_cat = str_replace('#', '', $_cat); $number[$_cat][$_bool][$_id] = trim($num); } $total = 0; for($i = $range_min; $i <= $range_max; $i++) { if(isset($number[$cat][$bool][$i])) { $total += $number[$cat][$bool][$i]; } } return $total; } } Called like this and written to a new html file in writeform.php $file = fopen($url, "w") or exit("Unable to open file!"); $stringData = ' calculate_range('UB', 0, 1090, 1099) ' ; fwrite($file, $stringData); fclose($file); Hope this helps you help med solve the problem. Strange thing is that when form.html and writeform.php are in the same directory all is fine but not when they are in different directories... Quote Link to comment https://forums.phpfreaks.com/topic/81845-solved-file-upload-problem/#findComment-415833 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.