PHP Conundrum
Posted: Tue Jun 06, 2006 12:28 pm
Hi there.
I just started PHP a week ago.
Was wondering, if some of you could answer this question.
The Idea
The page I am making gives information on products. Each product has it’s own folder named after it’s database ID number. In this folder are files that belong to the product.
How it works
On the main page you can add a new product. You give it a name and the PHP gives it an ID number. Then there is a big fat button that links them back to the main page. There they have to search for the product. Once they access the product's edit page they have to hit another big button that creates new directories and uploads files to that directory before they can edit the product's page.
Ideally
As you can see it is not very user-friendly.
Ideally the user hits the submit button on the create new product page and the script automatically creates the folders and uploads the files. The thing is, the script dose not know the ID number of the product yet.
Uploads new product to database (the folowing is only an example)
Now the person goes back. Searches for the product. Opens up the product’s edit page which has the product ID hidden in it. The user has to press a button. This then sends the product ID to the following code.
Creating dir and upload files (the folowing is only an example)
Is there a way to combine these codes?
I just started PHP a week ago.
The Idea
The page I am making gives information on products. Each product has it’s own folder named after it’s database ID number. In this folder are files that belong to the product.
How it works
On the main page you can add a new product. You give it a name and the PHP gives it an ID number. Then there is a big fat button that links them back to the main page. There they have to search for the product. Once they access the product's edit page they have to hit another big button that creates new directories and uploads files to that directory before they can edit the product's page.
Ideally
As you can see it is not very user-friendly.
Ideally the user hits the submit button on the create new product page and the script automatically creates the folders and uploads the files. The thing is, the script dose not know the ID number of the product yet.
Uploads new product to database (the folowing is only an example)
Code: Select all
<?
$Name=$_POST['new_product];
.
.
.
$addProduct = "INSERT INTO Product (Name) VALUES ('".$Name."')";
$result = mysql_query($addProduct);
?>Creating dir and upload files (the folowing is only an example)
Code: Select all
<?
$input=$_POST['productID'];
mkdir("Product/".$input."/", 0700);
mkdir("Product/".$input."/Images/", 0700);
$file = 'AAA/BBB/CCC.xxx';
$newfile = 'DDD'.$input.'/CCC.xxx';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
?>