compguru910 Posted August 15, 2008 Share Posted August 15, 2008 Ok, im having a slight problem. This is probably something really simple that I am overlooking, but bare with me. I have made a web app that a bodyshop is going to use to manage their customers vehicles. Well, its all working great until this. When you add a new vehicle to the website, it makes directories to keep the pictures seperated so that customers and insurance companies can download them, that all works (except for a little part thats kinda odd). So, the problem arises when you try to add a vehicle a second time for a second incident. Now, it still works, but I can see it would become a nuisance later. Since the folder has already been created for that license plate number (thats how the vehicles are tracked) it gives me an error, but all the other folders inside of that one (if they dont exist already) are created fine. This is the heirarchy of the folders License plate Make-Model-Year Incident Title So, if I try to add the vehicle again for another incident, it pops up an error saying directory already exists. Now, how do I keep that from happening. I know I should probably call a script to see if the directory exists, but I dont know the syntax. Secondly, I made it so that you dont have to track the images for the cars with a database by using this folder system. Pretty cool. It also assigns each image with its own unique name (timestamp). Well, this is all good until it comes down to determining the file type. Here is my code for that $file_type = $_FILES['pic']['type']; if ($file_type == "image/png") { $file_ext = ".png"; } elseif ($file_type == "image/jpeg") { $file_ext = ".jpg"; } elseif ($file_type == "image/gif") { $file_ext = ".gif"; } elseif ($file_type == "image/bmp") { $file_ext = ".bmp"; } else { print "File Type Not Supported"; exit(); } This works fine, most of the time. But I noticed that if I do it from different computers than mine it doesnt work sometimes, other times it will. Can anyone suggest a better, more error free way of detecting the file type? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/119765-testing-directories/ Share on other sites More sharing options...
chronister Posted August 15, 2008 Share Posted August 15, 2008 <?php $dirName = 'xy48xoee7'; // dummy license plate number if(is_dir($dirName)) { // the directory already exists, so just add stuff to it } else { // the directory does not exist, so create it and add stuff to it } ?> This is not exactly right as the path to $dirName needs to be the complete path. You can use $_SERVER['DOCUMENT_ROOT'].'/path/to/'.$dirName; as the path to make it easier. Nate Quote Link to comment https://forums.phpfreaks.com/topic/119765-testing-directories/#findComment-617120 Share on other sites More sharing options...
compguru910 Posted August 15, 2008 Author Share Posted August 15, 2008 Thanks, I figured it would be something simple along those lines. Anyone have any suggestions for the image type problem I am running into? Quote Link to comment https://forums.phpfreaks.com/topic/119765-testing-directories/#findComment-617271 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.