sid0972 Posted February 11, 2013 Share Posted February 11, 2013 (edited) here is the script i am using <?php session_start(); define ("MAX_SIZE","10000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { for($i=0; $i<count($_files['image']['name']);$i++) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } $directoryPath = "images/".$_SESSION['valid_user']; if (is_dir($directoryPath)) { echo "exists<br>"; $image_name=time().'.'.$extension; $newname="/images/".$_SESSION['valid_user']."/".$image_name; } else { echo "not exists"; $directorypaths = "images/".$_SESSION['valid_user']; mkdir($directorypaths, 0755); $newname="/images/".$_SESSION['valid_user']."/".$image_name; } $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy uunsuccessfull!</h1>'; echo "<a href=\"member.php\">Click</a>"; $errors=1; }}}}} if(isset($_POST['Submit']) && !$errors) { echo "<h1>File Uploaded Successfully! Try again!</h1>"; echo "<a href=\"member.php\">Click</a>"; } ?> <form name="newad" method="post" enctype="multipart/form-data" action="image_upload.php"> <table> <tr><td><input type="file" name="image"></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form> i copied this from somewhere and modified it a bit. I want it to check if a directory of the name of current user is already in the /images folder, and if not, it should create a directory by the name of current user and save images in there. So i added this part here $directoryPath = "images/".$_SESSION['valid_user']; if (is_dir($directoryPath)) { echo "exists<br>"; $image_name=time().'.'.$extension; $newname="/images/".$_SESSION['valid_user']."/".$image_name; } else { echo "not exists"; $directorypaths = "images/".$_SESSION['valid_user']; mkdir($directorypaths, 0755); $newname="/images/".$_SESSION['valid_user']."/".$image_name; } and i would take a guess that this part is not working. Any help is appreciated. Edited February 11, 2013 by sid0972 Quote Link to comment https://forums.phpfreaks.com/topic/274350-cant-get-image-upload-script-to-work/ Share on other sites More sharing options...
sid0972 Posted February 11, 2013 Author Share Posted February 11, 2013 i solved it i used this script and applied the same modification and everything works fine now Quote Link to comment https://forums.phpfreaks.com/topic/274350-cant-get-image-upload-script-to-work/#findComment-1411798 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.