herghost Posted April 28, 2009 Share Posted April 28, 2009 Hi all, I have this: <?php session_start(); //include('../include/auth.php'); include('../include/database.php'); $errmsg_arr = array(); $errflag = false; function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $userid = $_SESSION['SESS_USERID']; $Name = clean($_POST['Name']); $Tracks = clean($_POST['Tracks']); $qry = ("INSERT INTO banddisco (userid, albumno, Name, Tracks) VALUES ('$userid', '', '$Name', '$Tracks') "); $result = mysql_query($qry) or die(mysql_error()); $fields = array('Name'); foreach($fields as $var) { if (isset($_POST[$var])) $_SESSION[$var] = $_POST[$var]; } $sql = "SELECT * FROM user WHERE userid = $userid"; $result = mysql_query($sql) or die(mysql_error()); if ($result) { while ($row = mysql_fetch_array($result)) { $userid = $row["userid"]; if (is_dir('users/'.$userid) == FALSE) { mkdir('../users/'.$userid); mkdir('../temp/'.$userid); } if (is_dir('users/'.$userid) == TRUE) { if (isset($_POST['submit'])) { if (isset($_FILES['new_image'])) { $file_name = $_FILES['new_image']['name']; $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; $allowed_ext = "|jpg|png|gif|jpeg|svg|bmp|"; if (strpos($allowed_ext, "|".strtolower($file_ext)."|")===false) die("Extension: $file_ext is not allowed!"); $imagename = "$_SESSION[Name]"; $source = $_FILES['new_image']['tmp_name']; $target = "C:/wamp/www/fanjunky/users/$userid/$imagename"; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "C:/wamp/www/fanjunky/users/$userid/$imagepath"; $file = "C:/wamp/www/fanjunky/temp/$userid"; if($result) { header("location: ../member_home.php?disco=1"); exit(); }else { die(mysql_error()); } } } } } } ?> Which uploads some data to a database, and then is meant to check to see if a directory exists and then save the picture to it. However, I can not get it to work! Once the directory has been created I just get this message: Warning: mkdir() [function.mkdir]: File exists in C:\wamp\www\fanjunky\do\banddiscodo.php on line 40 Warning: mkdir() [function.mkdir]: File exists in C:\wamp\www\fanjunky\do\banddiscodo.php on line 41 the data uploads to the database fine, but no picture is stored. Can anyone shed any light? Am I fine in saving and calling a session on the same page? Quote Link to comment https://forums.phpfreaks.com/topic/156026-picture-saving-mkdir-help/ Share on other sites More sharing options...
premiso Posted April 28, 2009 Share Posted April 28, 2009 Try this for the if statement: if (!is_dir('users/'.$userid) && !file_exists('users/' . $userid)) { mkdir('../users/'.$userid); mkdir('../temp/'.$userid); } And see if that gets you better results. Quote Link to comment https://forums.phpfreaks.com/topic/156026-picture-saving-mkdir-help/#findComment-821408 Share on other sites More sharing options...
herghost Posted April 29, 2009 Author Share Posted April 29, 2009 Thanks for the reply, exactly the same though Quote Link to comment https://forums.phpfreaks.com/topic/156026-picture-saving-mkdir-help/#findComment-821478 Share on other sites More sharing options...
mikesta707 Posted April 29, 2009 Share Posted April 29, 2009 maybe try is_dir('users/'.$userid) === FALSE for certain functions, you have to use the "===" comparison operator (I think thats what they are called) to test if the return value is true or false. Im sure someone can give a better explanation to why than me, but im pretty sure it has to do with the type of the return value. some functions return 1 for true and 0 for false Quote Link to comment https://forums.phpfreaks.com/topic/156026-picture-saving-mkdir-help/#findComment-821482 Share on other sites More sharing options...
herghost Posted April 29, 2009 Author Share Posted April 29, 2009 No Luck Quote Link to comment https://forums.phpfreaks.com/topic/156026-picture-saving-mkdir-help/#findComment-821485 Share on other sites More sharing options...
mikesta707 Posted April 29, 2009 Share Posted April 29, 2009 maybe is_dir('../users/'.$userid ? sorry man but that code looks like it should work. it if helps though, for an upload script i made, to test if a directory existed i used the following $uname = strtolower($_SESSION['Username']); if (!file_exists('Uploads/' . $uname)) { mkdir('Uploads/'. $uname); } Quote Link to comment https://forums.phpfreaks.com/topic/156026-picture-saving-mkdir-help/#findComment-821491 Share on other sites More sharing options...
herghost Posted April 29, 2009 Author Share Posted April 29, 2009 ah getting somewhere! I had forgottem the ../ However, no error, just blank screen, and image does not upload. I have used the same upload script elsewhere on the site, and it works fine. So I am guessing the script is not running the lines after the mkdir has closed Quote Link to comment https://forums.phpfreaks.com/topic/156026-picture-saving-mkdir-help/#findComment-821495 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.