Help with Something.

Any problem with PHP can be disscused here
Post Reply
pryj
Posts: 56
Joined: Tue Dec 21, 2004 1:06 pm

Help with Something.

Post by pryj »

My friend got this script and gave it to me (he didnt make it). It's a simple little script that lets a user upload a file, but the file is put in a specific directory. I have very little php knoledge and so I do not know how to change the directory.

I'll paste the 3 php files and then, if possible, I'd like someone to show me how/where I can specify a location to upload the files to.

Here we go:


Index.php


PHP Code:
<html>
<head>
<title>PHP Uploader</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.text1 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: White;text-align : left;}
.text2 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: Silver;text-align : left;}
.titre1 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;font-weight: bold;color: #FFFFFF;}
.titre2 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;font-weight: bold;color: #cccccc;}
</style>
</head>

<body bgcolor="#525A73">
[img]header.gif[/img]
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="text1">
<form name="form1" method="post" action="uploadForm2.php">


Enter the number of uploads. Max is 9.</p>



<input name="uploadNeed" type="text" id="uploadNeed" maxlength="1">
</p>



<input type="submit" name="Button1" value="Ok">
</p>
</form>
</td>
</tr>
</table>
<font color="white">When you upload something, it is put in a moderation queue and will NOT be put online until I have seen, and approved it.</font>
</body>
</html>



uploadForm2.php


PHP Code:
<html>
<head>
<title>PHP Uploader|2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.text1 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: White;text-align : left;}
.text2 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: Silver;text-align : left;}
.titre1 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;font-weight: bold;color: #FFFFFF;}
.titre2 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;font-weight: bold;color: #cccccc;}
</style>
</head>

<body bgcolor="#525A73">
[img]header.gif[/img]
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="text1">
<form name="form1" enctype="multipart/form-data" method="post" action="processFiles.php">



<?
// start of dynamic form
$uploadNeed = $_POST['uploadNeed'];
for($x=0;$x<$uploadNeed;$x++){
?>
<input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>">
</p>
<?
// end of for loop
}
?>


<input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
<input type="submit" name="Submit" value="Upload!">
</p>
</form>
</td>
</tr>
</table>
</body>
</html>


processFiles.php


PHP Code:
<html>
<head>
<title>PHP Uploader|2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.text1 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: White;text-align : left;}
.text2 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: Silver;text-align : left;}
.titre1 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;font-weight: bold;color: #FFFFFF;}
.titre2 {font-family: Arial, Helvetica, sans-serif;font-size: 12px;font-weight: bold;color: #cccccc;}
</style>
</head>

<body bgcolor="#525A73">
[img]header.gif[/img]
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="text1">
<form name="form1" enctype="multipart/form-data">
<?
$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
// check if successfully copied
if($copy){
echo "$file_name | Uploaded!
";
}else{
echo "$file_name | borked!
";
}
} // end of loop
?>
</form>
</td>
</tr>
</table>
</body>
</html>



Thanks.


Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

i think this script upload the file to the same directory as your theese 3 files
Change in last file, where script processing uploads:
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name); //this is original


Here will be updated version, but i'm not sure if it will realy work, and dont forget to chmod uploads directory
$subdir="./subdir_name/";
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$subdir.$file_name);
notice underlined places

post here a message if it will help u
Image
Post Reply