jkewlo Posted April 15, 2009 Share Posted April 15, 2009 Hey me again ok so I am working on this uploader to upload images to a database and a directory the directory will be named as the user username which it all works but im getting this little error Warning: mkdir() [function.mkdir]: File exists in /uploadimage.php on line 7 The Directory is being created but what I cant figure out is a if statement or w/e to check if the directory is there and if it is upload the image and upload the path etc.. to the database if the Directory is not there create it and then upload the image path etc.. to the database. if anyone can figure something out please help me lol <?php session_start(); include("data/connect.php"); include("data/function.php"); $uploadDir = "user/". $_SESSION['myusername'] ."/"; mkdir("". $uploadDir ."/".$_SESSION["username"]."/", 0777); if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { $msg = "<span class='confirmationerror'><img src='img/x.gif'>Image was not uploaded!</span>"; exit; } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query = "UPDATE users SET name='". $fileName ."', size='". $fileSize ."', type='". $fileType ."', path='". $filePath ."' WHERE username='". $_SESSION['myusername'] ."'"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); $msg = "<span class='confirmationaccept'><img src='img/check.gif'>Image Uploaded Successful!</span>"; $_SESSION['message'] = $msg; } ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/154272-solved-uploader-and-using-mkdir/ Share on other sites More sharing options...
jkewlo Posted April 15, 2009 Author Share Posted April 15, 2009 no help? Quote Link to comment https://forums.phpfreaks.com/topic/154272-solved-uploader-and-using-mkdir/#findComment-811048 Share on other sites More sharing options...
premiso Posted April 16, 2009 Share Posted April 16, 2009 This seems too simple, but did you try to use is_dir for your if statement to see if the directory is already there ??? Quote Link to comment https://forums.phpfreaks.com/topic/154272-solved-uploader-and-using-mkdir/#findComment-811092 Share on other sites More sharing options...
jkewlo Posted April 16, 2009 Author Share Posted April 16, 2009 thats the thing i dont know how i would do the if statement for it Quote Link to comment https://forums.phpfreaks.com/topic/154272-solved-uploader-and-using-mkdir/#findComment-811170 Share on other sites More sharing options...
keeB Posted April 16, 2009 Share Posted April 16, 2009 if (is_dir($userDir)) { // directory exists } else { echo 'there was an error. let me know about it, etc'; } Quote Link to comment https://forums.phpfreaks.com/topic/154272-solved-uploader-and-using-mkdir/#findComment-811190 Share on other sites More sharing options...
jkewlo Posted April 16, 2009 Author Share Posted April 16, 2009 Hem i Fixed it i just moved the makdr() to the bottom so i could have a header("location") also. and it working fine now thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/154272-solved-uploader-and-using-mkdir/#findComment-811195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.