softy123 0 Newbie Poster

I am new to php hence I ask sorry beforehand.

we use company's backup restore utility. It asks the user the id no. and it creates if it not there, and uploads the pdf files into id folder.
The server is Apache with php.
The utility first connects create.php to create folder of that id if it is not there. then it connects to upload php to upload file.
Here is the actual interaction with server.

POST /create.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: secureit ver2.4
Host: 192.168.27.6
Content-Length: 28
Cache-Control: no-cache
uploaddir=uploads/ID2772534/


HTTP/1.1 200 OK
Date: Wed, 16 Sep 2009 14:40:27 GMT
Server: Apache/2
X-Powered-By: PHP/5.2.10
Vary: Accept-Encoding,User-Agent
Content-Length: 268
Content-Type: text/html

#!/usr/local/bin/php
<br />
<b>Warning</b>: opendir(uploads/ID2772534/) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: No such file or directory in <b>/home/public_html/create.php</b> on line <b>4</b><br />

POST /upload.php HTTP/1.1
Content-Type: multipart/form-data; boundary=867865JGEI76I4GJR7847876IUR76
User-Agent: secureit ver2.4
Host: 192.168.27.6
Content-Length: 460316
Cache-Control: no-cache

--867865JGEI76I4GJR7847876IUR76
Content-Disposition: form-data; name="uploaddir"

uploads/ID2772534/
--867865JGEI76I4GJR7847876IUR76
Content-Disposition: form-data; name="filename"; filename="Report1232DI20030224064714.pdf"
Content-Type: text/plain
Content-Transfer-Encoding: binary


HTTP/1.1 200 OK
Date: Wed, 16 Sep 2009 14:40:36 GMT
Server: Apache/2
X-Powered-By: PHP/5.2.10
Vary: Accept-Encoding,User-Agent
Content-Length: 116
Content-Type: text/html

#!/usr/local/bin/php
File Report1232DI20030224064714.pdf is valid, and was successfully uploaded to uploads/ID2772534/

As it can be seen above, the form submits the value "uploaddir=uploads/ID2772534/"

Then how to code php that should accept "id" as a parameter or variable and create the folder accordingly.

And make a upload.php which accepts id as variable of this value "uploaddir=uploads/ID2772534/" and uploads the files accordingly to id folder.

For testing I made "create php" but it does not work. the code is

<? 
if ( !file_exists($uploaddir) )
{
    mkdir($uploaddir ,0777 );
}
 ?>

And for upload.php , following is the code.

<?php
define ( '$uploaddir', 'uploads' ); 
$fileObject = $_FILES ['Filedata'];  
$fileSize = ( double ) $fileObject ['size']; 
$fileName = $fileObject ['name'];  
$fileType = strtolower ( pathinfo ( $fileName, PATHINFO_EXTENSION ) ); 
$fileTempPath = $fileObject ['temp']; 
$fileUploadPath = rtrim ( $uploaddir, '/' ) . '/' . basename ( $fileName ); 
if (move_uploaded_file ( $fileTempPath, $fileUploadPath )) {
echo "$fileName is valid, and was successfully uploaded to uploads/"; 
} else {
    die ( "Error uploading the file! $fileName" );
}
?>

I have created folders namely "uploads" and " temp" with chmod of 0777 on the local webserver.
However I am unable to make them run. Kindly help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.