Jump to content

[noob] creating and populating directories


dftg

Recommended Posts

Hey everyone. I'm still pretty wet behind the ears when it comes to php, so let me just say thanks in advance.

 

I'm trying to write a php script that will:

 

[*]create a directory with a name that is either the current date or a name of my choosing.

[*]accept a zip file upload into that directory.

[*]unzip the file so it's just the files within the directory.

..and that's enough to start off. Here's my code so far:

 

part 1:

<html>
<head>
<title>upload part 1</title>
</head>
<body> 
<center>
<h1>Upload form part 1</h1>
<!--specify form action for html-->
<form action="upload2.php" method="post">
<?php 
// create new folder for event
$folder_name = date("mdy");

?>
<!--textarea for inputting folder name with preset of current date.--> 
<p>Folder name?
<input type="text" name="folder_name" size="30" maxlength="50" value=" <?php echo $folder_name; ?> "
<!--upload a file-->
<input type="submit" name="submit" value="Make directory!" />
</form>
</center>
</body>
</html>

 

part 2:

 

<?php
$dirname = $_POST['folder_name'];

if (is_dir($dirname) === true){
echo  $dirname . " exists";

} else {
mkdir("$dirname", 0755);
}
if (isset($_POST['submitted'])) {

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], '$dirname')) {
	echo "the file " . basename( $_FILES['UPLOADEDFILE']['NAME']) . " has been uploaded.";

} else {
	echo "problem uploading/moving file.";
	} 

	echo '<p><font color="red">Please upload a zip file.</font></p>';
} // End of the submitted conditional.
?>
<html>
<body>
<form enctype="multipart/form-data" action="upload2.php" method="post">

<input type="hidden" name="MAX_FILE_SIZE" value="3000000">

<fieldset><legend>Select a zip file to be uploaded:</legend>

<p><b>File:</b> <input type="file" name="upload" /></p>

</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</body>
</html>

 

Currently I'm getting the error message "Warning: mkdir() [function.mkdir]: No such file or directory in /home/content/G/r/a/Gravid/html/headfirst/uploadtest.php on line 8" and I've tried different things and I'm not sure why I'm getting that. Any thoughts?

 

A couple more questions...

 

I pretty much modified some code I found in the peachpit press visual quickstart guide to php6 and mysql5, and as a result I don't understand something about this code. the part where it says "['uploaded']['tmp_name']" - what do the "uploaded" and "tmp_name" mean and why are they there?

 

Thanks again.

 

Link to comment
Share on other sites

I seem to be getting a different result based on what browser I'm using, I get an error message in firefox, and pretty much almost no results outside of the basic html printing out when I use IE.  :confused:

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.