Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("../include/session.php");
- // Your file name you are uploading
- $file_name = $HTTP_POST_FILES['avatar'];
- $userNameToSave = $session->username;
- if (rename($HTTP_POST_FILES['avatar']['name'] , $userNameToSave)){
- echo "rename successful";
- }else {
- echo "rename failed";
- }
- //set where you want to store files
- //in this example we keep file in folder upload
- //$userNameToSave = new upload file name
- //for example upload file name cartoon.gif . $path will be upload/cartoon.gif
- $path= "../users/".$userNameToSave."/".$userNameToSave;
- if($avatar !=none)
- {
- if(copy($HTTP_POST_FILES['avatar']['tmp_name'], $path))
- {
- $host="localhost"; // Host name
- $username="root"; // Mysql username
- $password="757794000708"; // Mysql password
- $db_name="IDEA"; // Database name
- $tbl_name="users"; // Table name
- // Connect to server and select database.
- mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- $avatar="../users/".$userNameToSave."/".$userNameToSave.".jpg";
- $sql="INSERT INTO $tbl_name(avatar)VALUES('$avatar')";
- $result=mysql_query($sql);
- if($result){
- echo "Successful<BR>";
- echo "<a href=../main_page.php>Back to Profile</a>";
- }
- else {
- echo "ERROR WITH COPYING TO DATABASE";
- }
- mysql_close();
- }
- else
- {
- echo "ERROR WITH UPLOADING FILE<br>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement