Jump to content

Archived

This topic is now archived and is closed to further replies.

thibz21

need help

Recommended Posts

i'm beginner in PHP and i have some problems here. this is my coding:

<?
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 0;
}

if ($page == "1")
{
$filename = addslashes($_POST['filename']);
if ($filename=="")
{
echo("*** No information given! ***");
}
else
{
$data = file ( '$filename' ); 
echo("*** hello!! ***<br>");
echo("*** $filename ***");
}
}
else
{
?>
<p>&nbsp;</p>
<p>&nbsp;</p>
<center>
<form name= "form1" form method="post"action="<?=$_SERVER['PHP_SELF']?>?page=1"enctype="multipart/form-data?page=1">
<p>
<input type="file" name="filename">
</p>
<p>&nbsp;</p>
<p>
<input name="Submit" type="submit" id="Submit" value="Grade" onkeypress="Check()">
//<input type="hidden" id="formaction" value="uploadNow">
<input name="reset" type="reset" id="reset" value="Clear">
</p>
</form>
</center>
<?
}
?>

and the output is here:

Warning: file($filename) [function.file]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\grade.php on line 20
*** hello!! ***
*** C:\\\\Documents and Settings\\\\user\\\\Desktop\\\\hardware.txt ***

i need to open a file and the location so shown with many slashes (\\\\). why this happen and how to solve this. if u have any other coding that does solve this problem. plz let me know. and since i'm a beginner, plz give full instruction on wat to do, cause i might don't know. advance thanx for ur help.

Share this post


Link to post
Share on other sites
Try removing addslashes() for a second to debug your result.

Share this post


Link to post
Share on other sites
i appreciate ur help... thanx... ur advise worked but still have few problems

from:
$filename = addslashes($_POST['filename']);

i changed to:
$filename = $_POST['filename'];

and the output was:
Warning: file($filename) [function.file]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\grade.php on line 20
*** hello!! ***
*** C:\\Documents and Settings\\user\\Desktop\\navz.txt ***

the slashes were less... but there is one more problem... i cannot ignore the whole...
//$filename = addslashes($_POST['filename']);
because it will not read the filename inserted.... so how? help... thanx...

Share this post


Link to post
Share on other sites
Wait a sec. What exactly are you trying to do? You realise that if you move this code to a server it will not work? I mean, you wont be able to open a file on the clients machine.

Another problem is you need double quotes around $filename. I don't know how your code is working at all.

[code=php:0]
$data = file ( "$filename" );
[/code]

can you post all your current code and any errors?

Share this post


Link to post
Share on other sites
the whole code is above there.... actually this code will in a server and the client pc will access that page to grade the student according to the marks in the file.... so.... that's the coding about... how am i suppose to do that... i'm just a beginner in PHP... i hope u might help... thanx...

Share this post


Link to post
Share on other sites
You will need to upload the file to the server.

Share this post


Link to post
Share on other sites
There is a tutorial on [url=http://www.phpfreaks.com/tutorials/36/0.php]this site[/url] which will show you how to upload an image... the process is the same.

Share this post


Link to post
Share on other sites
thanx... the double quating (") help me to solve the problem to open the file... thanx bro... but i still need to know how this code will work... i mean... i know i made a mistake... i know this won't work because when we accessing the server and the client pc have to send that file to the server to generate the grade into the file and to be send back to client pc... how do i do that?

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=104570.msg417266#msg417266 date=1155798995]
There is a tutorial on [url=http://www.phpfreaks.com/tutorials/36/0.php]this site[/url] which will show you how to upload an image... the process is the same.
[/quote]

thanx alot bro... i really appreciate ur help... i'll refer that web u gave me.... any problems i'll get back to u later... i hope u don't mind i asking question... thanx again bro.... later...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.