hyperlink and upload in PHP

Reply

Join Date: Mar 2008
Posts: 22
Reputation: eparse is an unknown quantity at this point 
Solved Threads: 0
eparse eparse is offline Offline
Newbie Poster

hyperlink and upload in PHP

 
0
  #1
Mar 4th, 2008
hi for all the PHP experts here, i have couple of questions that keeps me feel frustrating..

first of all, may i know how to insert a link within PHP echo?
for example, i have a function which is used to validate the username, if the username is incorrect, i need to echo a link to let the user back to the login page, and if the username is admin, i will need to direct it to the admin page, if username is user, then it will be the default page i'd created in the form's action. Here is the code:

  1. <?php
  2. session_start();
  3. $_SESSION['name']=$_POST['name'];
  4. $_SESSION['password']=$_POST['password'];
  5. $_SESSION['status']=$_POST['status'];
  6. if($_POST['name']=="user" || $_POST['name']=="admin")
  7. {
  8. // i need a link here to the pages
  9. echo "Your username is: ".$_POST['name'];
  10. }
  11. else
  12. {
  13. die('The username provided is not valid. Please provide a correct username.');
  14. }
  15.  
  16. if(strlen($_POST['password'])>=5 && $_POST['password']=="admin123" || $_POST['password']=="user123")
  17. {
  18. echo " with password: ".$_POST['password'];
  19. }
  20. else
  21. {
  22. die('.The password provided is not valid. Please provide a a correct password.');
  23. }
  24. ?>

the second question is, about the upload, i tried to upload the file using the code shown below but unsuccessfully, here is the code:
  1. <form enctype="multipart/form-data" action="uploader.php" method="POST">
  2. <input type="hidden" name="MAX_FILE_SIZE" value="100000" >
  3. <h1>Choose a file to upload:</h1>
  4. <div><label><input name="uploadedfile" type="file" ><input type="submit" value="Upload File" ></label>
  5. </div></form>

and for the uploader.php code:
  1. <?php
  2. $uploaddir = 'http://xxxx.xxxxxxx.com/phptryingnew_1/upload/files/';
  3. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  4. echo "<p>";
  5. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  6. echo "File is valid, and was successfully uploaded.\n";
  7. } else {
  8. echo "Upload failed";
  9. }
  10. echo "</p>";
  11. echo '<pre>';
  12. echo 'Here is some more debugging info:';
  13. print_r($_FILES);
  14. print "</pre>";
  15. ?>

is the code correct? Thanks for helping...
Last edited by eparse; Mar 4th, 2008 at 4:50 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: hyperlink and upload in PHP

 
0
  #2
Mar 4th, 2008
Hello,
For your first question try something like this:
echo "<a href='./page_to_redirect.php'>Click here</a>";

for your second question try to use copy() function. also do you have writing permission on the server (for the folder where you try to upload)?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 22
Reputation: eparse is an unknown quantity at this point 
Solved Threads: 0
eparse eparse is offline Offline
Newbie Poster

Re: hyperlink and upload in PHP

 
0
  #3
Mar 4th, 2008
well, thanks for ur contribution, however

  1. echo "<a href='./page_to_redirect.php'>Click here</a>";

doesnt help.

for part of the function shown below, i cant get the link.....

  1. else
  2. {
  3. die ('Sorry. Your username and password is invalid. Please try again.');
  4. echo "<a href='http://evios.freeweb7.com/phptryingnew_1/upload/index.php'>Click here back to login
  5.  
  6. page.</a>";
  7. }

However if the code changed to this:
  1. else
  2. {
  3. echo "Sorry. Your username and password is invalid. Please try again.";
  4. echo "<a href='http://evios.freeweb7.com/phptryingnew_1/upload/index.php'>Click here back to login page.</a>";
  5. }

i can see the hyperlink, but it already direct to the next page tho the username is invalid....
any mistakes here?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: hyperlink and upload in PHP

 
0
  #4
Mar 4th, 2008
die() function its similar to exit() so the code after the command it won't be executed.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 22
Reputation: eparse is an unknown quantity at this point 
Solved Threads: 0
eparse eparse is offline Offline
Newbie Poster

Re: hyperlink and upload in PHP

 
0
  #5
Mar 4th, 2008
well, now i knew die() means exit(), and my first problem solved. Thanks. Anyway, what is copy () function? Any clue on it? Thanks...
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: hyperlink and upload in PHP

 
0
  #6
Mar 4th, 2008
here are more details about the copy() function.
try to use physical path when referring to folder and also check if you have writing permission on that folder.
Last edited by silviuks; Mar 4th, 2008 at 6:04 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 22
Reputation: eparse is an unknown quantity at this point 
Solved Threads: 0
eparse eparse is offline Offline
Newbie Poster

Re: hyperlink and upload in PHP

 
0
  #7
Mar 4th, 2008
ok..thanks..however..does my upload code correct? or juz the server side permission?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: hyperlink and upload in PHP

 
0
  #8
Mar 4th, 2008
Originally Posted by eparse View Post
ok..thanks..however..does my upload code correct? or juz the server side permission?
your code seems to be correct ... (except the part with $uploaddir = "http://.....")
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 22
Reputation: eparse is an unknown quantity at this point 
Solved Threads: 0
eparse eparse is offline Offline
Newbie Poster

Re: hyperlink and upload in PHP

 
0
  #9
Mar 4th, 2008
last request....i try to use cytype for numbers validation...
because i am currently working on a form for clamming money, hence i need to validate the amount user enter, below is the code:
  1. if (cytype_digit('$amount'))
  2. {
  3. echo "This does not consist of only digits.";
  4. }
  5. else
  6. {
  7. echo "This cosists of only digits.";
  8. }
however i get this message:
Fatal error: Call to undefined function cytype_digit() in /www/freeweb7.com/e/v/i/evios/htdocs/phptryingnew_1/upload/claim_try.php on line 10
does it mean my web hosting doesnt include this cytype? any other method for validating numbers?? Thanks....
P/S: Any directories available for me to upload my files so that i can debug my upload.php..thanks again..
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: hyperlink and upload in PHP

 
0
  #10
Mar 4th, 2008
Originally Posted by eparse View Post
last request....i try to use cytype for numbers validation...
because i am currently working on a form for clamming money, hence i need to validate the amount user enter, below is the code:
  1. if (cytype_digit('$amount'))
  2. {
  3. echo "This does not consist of only digits.";
  4. }
  5. else
  6. {
  7. echo "This cosists of only digits.";
  8. }
however i get this message:
Fatal error: Call to undefined function cytype_digit() in /www/freeweb7.com/e/v/i/evios/htdocs/phptryingnew_1/upload/claim_try.php on line 10
does it mean my web hosting doesnt include this cytype? any other method for validating numbers?? Thanks....
P/S: Any directories available for me to upload my files so that i can debug my upload.php..thanks again..
i can't figure out why you get this error (unless you use a older version of php - like 3.x), but be aware that your if statement will display you "This does not consist of only digits." when its true.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC