-
How do I upload a file to the same directory as my 'upload.php' file?
Is it possible to do this without having knowning the hole filesystem tree.
I've tried alot of things but don't get it to work
June 10th, 2000, 02:14 AM
-
Use the File Data Type to do this.
<html>
<body>
<form enctype="multipart/form-data" method="post"
action="<?php echo $PHP_SELF ?>">
<input type="File" name="blah" size="25"><br>
<input type="submit" name="submit" value="Upload">
</form>
<?php
if ($submit) {
exec("cp $blah complete path of your folder/$filename");
//syntax for cp - cp Uploading File, Path where the file to be Uploaded.
Enjoy
Raghu.
}
?>
</body>
</html>
June 10th, 2000, 02:16 AM
-
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by raghuram:
Use the File Data Type to do this.
<html>
<body>
<form enctype="multipart/form-data" method="post"
action="<?php echo $PHP_SELF ?>">
<input type="File" name="blah" size="25"><br>
<input type="submit" name="submit" value="Upload">
</form>
<?php
if ($submit) {
exec("cp $blah complete path of your folder/$filename");
//syntax for cp - cp Uploading File, Path where the file to be Uploaded.
}
?>
</body>
</html>
[/quote]
Enjoy
Raghu.
June 10th, 2000, 08:52 AM
-
Hi Raghu,
I tried your code but somehow it didn't work with me. Maybe I didn't get the path-thing right, but I changed the code somewhat and now I can upload a file into a directory 'files', which is located in the same directory as my upload-script. So far so good! 
The problem is though I don't know how I can give the uploaded file the same name as the original. $blah is always C:WindowsTempPhp2 with me, so with my current script I get a file called php2. Is there a way to get this right?
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<html>
<body>
<form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF ?>">
<input type="File" name="blah" size="25"><br>
<input type="submit" name="submit" value="Upload">
</form>
<?php
if ($submit) {
$dir = "files";
$filename = basename($blah);
if (!copy($blah, $dir.$filename)) {
print( "Oops! Something went wrong!");
}
}
?>
</body>
</html>
[/code]
Mirax