jnerotrix Posted December 5, 2008 Share Posted December 5, 2008 Whats wrong with my code i want if the file exists to display what it says to display else display other info but it always displays the form heres the code i have so far <?php $ip = $_SERVER['REMOTE_ADDR']; $useripdata = '/ip/' . $ip .'.txt'; if (file_exists($useripdata)) { foreach (file("/ip/$ip.txt") as $line) { echo '$' . $line; } for ($i=0; $i < $numTimes; $i++) { echo '<object width="$setwidth" height="$setheight""><param name="movie" value="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1"></param><param name="allowFullScreen" value="false"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1$autoplay" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false" width="$setwidth" height="$setheight"></embed></object>'; } echo "<meta http-equiv='refresh' content='$reloadtime'>"; } else { if (isset($_POST['action'])) { $numTimes = (isset($_POST['times']) && is_numeric($_POST['times']))?$_POST['times']:10; $shorturl = $_POST['url']; $autoplay = "&autoplay=1"; $reloadtime = $_POST['reloadtime']; $setwidth = $_POST['setwidth']; $setheight = $_POST['setheight']; $shorturl = $_POST['url']; $fullurl = "http://www.youtube.com/watch?v=$shorturl"; $myFile = "./ip/$ip.txt"; $fh = fopen($myFile, 'w'); $stringData = "numTimes = 10 \n"; fwrite($fh, $stringData); $stringData = "shorturl = $shorturl \n"; fwrite($fh, $stringData); $stringData = "autoplay = $autoplay \n"; fwrite($fh, $stringData); $stringData = "reloadtime = $reloadtime \n"; fwrite($fh, $stringData); $stringData = "setwidth = $setwidth \n"; fwrite($fh, $stringData); $stringData = "setheight = $setheight \n"; fwrite($fh, $stringData); $stringData = "fullurl = $fullurl \n"; fwrite($fh, $stringData); fclose($fh); function check_if_valid($fullurl) { $res = (($check = @fopen($fullurl, ‘r’)) === false) ? false : @fclose($check); return ($res == TRUE) ? VIDEO_IS_VALID:VIDEO_IS_INVALID ; } if ($HTTP_POST_VARS["submitted"] == "yes"){ echo "<meta http-equiv='refresh' content='$reloadtime'>"; } for ($i=0; $i < $numTimes; $i++) { echo '<object width="$setwidth" height="$setheight""><param name="movie" value="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1"></param><param name="allowFullScreen" value="false"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1$autoplay" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false" width="$setwidth" height="$setheight"></embed></object>'; } } } $self = $_SERVER['PHP_SELF']; echo "<table border='1'>"; echo "<form action='$self' method='post'>"; echo "<tr>"; echo "<td>Video Url:<input type='text' readonly='1' value='http://www.youtube.com/watch?v=' size='30'><input type='Text' name='url'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>(Number)<input type='text' name='times' value='10'> of Times to Display Video in <input type='text' name='reloadtime' value='5'>(Seconds)</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Set Width <input type='text' name='setwidth' value='425'> Set Height <input type='text' name='setheight' value='344'>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' valign='center'><input type='submit' name='action' value='Submit'>"; echo "<input type='hidden' name='submitted' value='yes'>"; echo "</td>"; echo "</tr>"; echo "</form>"; echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/135733-if-file-exists-display-this-else-display-that/ Share on other sites More sharing options...
jnerotrix Posted December 6, 2008 Author Share Posted December 6, 2008 I changed the code a bit: $useripdata = "/ip/$ip.txt"; instead of $useripdata = '/ip/' . $ip .'.txt'; This but still doesnt work correctly So the Code Looks Like This <?php $ip = $_SERVER['REMOTE_ADDR']; $useripdata = "/ip/$ip.txt"; if (file_exists($useripdata)) { foreach (file("/ip/$ip.txt") as $line) { echo '$' . $line; } for ($i=0; $i < $numTimes; $i++) { echo '<object width="$setwidth" height="$setheight""><param name="movie" value="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1"></param><param name="allowFullScreen" value="false"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1$autoplay" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false" width="$setwidth" height="$setheight"></embed></object>'; } echo "<meta http-equiv='refresh' content='$reloadtime'>"; } else { if (isset($_POST['action'])) { $numTimes = (isset($_POST['times']) && is_numeric($_POST['times']))?$_POST['times']:10; $shorturl = $_POST['url']; $autoplay = "&autoplay=1"; $reloadtime = $_POST['reloadtime']; $setwidth = $_POST['setwidth']; $setheight = $_POST['setheight']; $shorturl = $_POST['url']; $fullurl = "http://www.youtube.com/watch?v=$shorturl"; $myFile = "./ip/$ip.txt"; $fh = fopen($myFile, 'w'); $stringData = "numTimes = 10 \n"; fwrite($fh, $stringData); $stringData = "shorturl = $shorturl \n"; fwrite($fh, $stringData); $stringData = "autoplay = $autoplay \n"; fwrite($fh, $stringData); $stringData = "reloadtime = $reloadtime \n"; fwrite($fh, $stringData); $stringData = "setwidth = $setwidth \n"; fwrite($fh, $stringData); $stringData = "setheight = $setheight \n"; fwrite($fh, $stringData); $stringData = "fullurl = $fullurl \n"; fwrite($fh, $stringData); fclose($fh); function check_if_valid($fullurl) { $res = (($check = @fopen($fullurl, ‘r’)) === false) ? false : @fclose($check); return ($res == TRUE) ? VIDEO_IS_VALID:VIDEO_IS_INVALID ; } if ($HTTP_POST_VARS["submitted"] == "yes"){ echo "<meta http-equiv='refresh' content='$reloadtime'>"; } for ($i=0; $i < $numTimes; $i++) { echo '<object width="$setwidth" height="$setheight""><param name="movie" value="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1"></param><param name="allowFullScreen" value="false"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $shorturl . '&hl=en&fs=1$autoplay" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false" width="$setwidth" height="$setheight"></embed></object>'; } } } $self = $_SERVER['PHP_SELF']; echo "<table border='1'>"; echo "<form action='$self' method='post'>"; echo "<tr>"; echo "<td>Video Url:<input type='text' readonly='1' value='http://www.youtube.com/watch?v=' size='30'><input type='Text' name='url'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>(Number)<input type='text' name='times' value='10'> of Times to Display Video in <input type='text' name='reloadtime' value='5'>(Seconds)</td>"; echo "</tr>"; echo "<tr>"; echo "<td>Set Width <input type='text' name='setwidth' value='425'> Set Height <input type='text' name='setheight' value='344'>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' valign='center'><input type='submit' name='action' value='Submit'>"; echo "<input type='hidden' name='submitted' value='yes'>"; echo "</td>"; echo "</tr>"; echo "</form>"; echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/135733-if-file-exists-display-this-else-display-that/#findComment-707233 Share on other sites More sharing options...
bgadberry Posted December 6, 2008 Share Posted December 6, 2008 the first thing I can see wrong with this appears to be your foreach statment. foreach (file("/ip/$ip.txt") as $line) { echo '$' . $line; } You look as though you are redoing a step. couldnt you put foreach (file($useripdata) as $line) { echo '$' . $line; } as $useripdata is already formatted to the string you are looking for? Link to comment https://forums.phpfreaks.com/topic/135733-if-file-exists-display-this-else-display-that/#findComment-707234 Share on other sites More sharing options...
jnerotrix Posted December 6, 2008 Author Share Posted December 6, 2008 ok but that doesnt fix the problem of why it stills shows the form if that file exists ------------ because i have the file existing for my ip but when i visit the page it still shows the form Link to comment https://forums.phpfreaks.com/topic/135733-if-file-exists-display-this-else-display-that/#findComment-707237 Share on other sites More sharing options...
bgadberry Posted December 6, 2008 Share Posted December 6, 2008 It appears it still shows the form because the form is OUTSIDE the if/then/else statement. Try putting it inside the else section of that. Link to comment https://forums.phpfreaks.com/topic/135733-if-file-exists-display-this-else-display-that/#findComment-707250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.