Jump to content

directory path with variables


moosey_man1988
Go to solution Solved by moosey_man1988,

Recommended Posts

Hi There

 

I'm pretty New to php im trying to creat an upload page that will store the file in the customers variable (Reference number)

 

This is what im having trouble with

 

$path = "uploads/".$customernumber."/".$dateFile."";

 

getting that second / to work..

 

here's the full code of what im trying to achieve (upload a file to a upload/$customernumber/date/test.txt)

please bear in mind this is a php page called by another php page so there may be some variables missing

 

$directory = is_dir($path);
$dateFile= date('Y-m-d');
$path = "uploads/".$customernumber."/".$dateFile."";
 
$extension = end(explode(".", $_FILES["file"]["name"]));
 
if ($_FILES["file"]["size"] > 2000000 ) {
die ('please provide a smaller file size.' );
}
 
if ( !( in_array($extension, $allowedExts))) {
die('Please Provide a Different File Type.');
}
 
if ($directory == false) {
    mkdir($path, 0777);
}
 
the upload page itself works but i just need to get the directories right.
Link to comment
Share on other sites

Where are you setting $customernumber? Make sure you have error display turned on and see if the code is throwing any errors. You may also want to simply echo out $path and make sure you're looking where you think you're looking.

 

Other thing, please be sure to use the code button [ <> ] in the text editor when posting code. It makes things easier to read.

Link to comment
Share on other sites

  • Solution

Hey very sorry i fixed, the issue was i was trying to makdir 2 directories (face palm)!

 

creates another variable with the first directory and then another with both and told the php script to mkdir the first directory THEN the second one,

 

so all along it wasnt that line.

 

Here's the result code:

$directory = is_dir($path);
$dateFile= date('Y-m-d');
$customerPath = "uploads/".$customernumber."";
$path = "uploads/".$customernumber."/".$dateFile."";

$extension = end(explode(".", $_FILES["file"]["name"]));

if ($_FILES["file"]["size"] > 2000000 ) {
	die ('please provide a smaller file size.' );
}

if ( !( in_array($extension, $allowedExts))) {
	die('Please Provide a Different File Type.');
}

if ($directory == false) {
	mkdir($customerPath, 0777);
    mkdir($path, 0777);
}

if (in_array( $_FILES["file"]["type"], $AllowedMimeTypes) )
{
$fileName=$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], "$path/" . $_FILES["file"]["name"]);
}
else
{
die ('Please Provide Another File Type');
}
}
?>
Link to comment
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.