By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,578 Members | 814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,578 IT Pros & Developers. It's quick & easy.

create directory for upload file

P: 89
Hello all

I have a php script that uploads a file from a form into a directory. The directory is automatically created through the script.

But the upload file is not put in to the directory, but outside....

Can anyone tell what i am doing wrong....?? And perhaps tell me what to do to put the file into the created directory...?

Here is my code:

[PHP]<?php

// Your file name you are uploading
$file_name = $HTTP_POST_FILES['ufile']['name'];

// random 4 digit to add to our file name
// some people use date and time in stead of random digit
$random_digit=rand(0000,99999);

mkdir("D:\\Webs\\printline-webshop.eu\\httpdocs\\searchpro\\data\\".$random_d igit) or die ("Could not make directory");

//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables

$new_file_name=$random_digit.$file_name;

//set where you want to store files
//in this example we keep file in folder upload
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "D:\\Webs\\printline-webshop.eu\\httpdocs\\searchpro\\data\\".$new_file _name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{


//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file

}
else
{
echo "Error";
}
}
?>[/PHP]

Any help would gladly be appreciated...
Sep 10 '08 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

First of all, the $HTTP_POST_FILES array is old and shouldn't be used.
Use the $_FILES super-global instead.

The reason why your file isn't put into the folder is because you are not putting it into the folder. (obviously).

What you are actually doing is:
You create a random number.
Then you create a new folder using that number (bad idea btw).
Finally, you add that number to the file name and save it, rather than adding the file into the new folder.

Take a look at the examples in the manual.
You could easily modify one of them into what you need.
Sep 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.