Jump to content

directory path with variables


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
https://forums.phpfreaks.com/topic/296521-directory-path-with-variables/
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.

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');
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.