Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/119765-testing-directories/
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/119765-testing-directories/#findComment-617120
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.