Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <?php
  2. include("../include/session.php");
  3. // Your file name you are uploading
  4.  
  5. $file_name = $HTTP_POST_FILES['avatar'];
  6. $userNameToSave = $session->username;
  7.  
  8. if (rename($HTTP_POST_FILES['avatar']['name'] , $userNameToSave)){
  9. echo "rename successful";
  10. }else {
  11. echo "rename failed";
  12. }
  13.  
  14.  
  15. //set where you want to store files
  16. //in this example we keep file in folder upload
  17. //$userNameToSave = new upload file name
  18. //for example upload file name cartoon.gif . $path will be upload/cartoon.gif
  19. $path= "../users/".$userNameToSave."/".$userNameToSave;
  20. if($avatar !=none)
  21. {
  22. if(copy($HTTP_POST_FILES['avatar']['tmp_name'], $path))
  23. {
  24.  
  25. $host="localhost"; // Host name
  26. $username="root"; // Mysql username
  27. $password="757794000708"; // Mysql password
  28. $db_name="IDEA"; // Database name
  29. $tbl_name="users"; // Table name
  30.  
  31. // Connect to server and select database.
  32. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  33. mysql_select_db("$db_name")or die("cannot select DB");
  34.  
  35. $avatar="../users/".$userNameToSave."/".$userNameToSave.".jpg";
  36.  
  37. $sql="INSERT INTO $tbl_name(avatar)VALUES('$avatar')";
  38. $result=mysql_query($sql);
  39.  
  40. if($result){
  41. echo "Successful<BR>";
  42. echo "<a href=../main_page.php>Back to Profile</a>";
  43. }
  44. else {
  45. echo "ERROR WITH COPYING TO DATABASE";
  46. }
  47. mysql_close();
  48. }
  49. else
  50. {
  51. echo "ERROR WITH UPLOADING FILE<br>";
  52. }
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement