Jump to content


Photo

Help with upload script.


  • Please log in to reply
1 reply to this topic

#1 MunE

MunE
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 20 September 2006 - 03:18 AM

Hi, I was wondering how I would get this upload script (3 pages) to upload to a certain folder, for example, a "downloads" folder.  I got this script a few days ago and it works fine as it is, but now I have a need to upload to certain folders from a central location.
Can anyone help?  :S


uploadForm1.php
<form name="form1" method="post" action="uploadForm2.php">
	Enter number of replays<br>
	<input name="uploadNeed" type="text" id="uploadNeed" maxlength="1"><br>
	<input type="submit" name="Submit" value="Submit">
</form>

uploadForm2.php
<form name="form1" enctype="multipart/form-data" method="post" action="processFiles.php">
	Select file location:<br>
<?
// start of dynamic form
$uploadNeed = $_POST['uploadNeed'];
for($x=0;$x<$uploadNeed;$x++){
?>
	<input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>">
<?
// end of for loop
}
?>
	<input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>"><br>
	<input type="submit" name="Submit" value="Submit">
</form>

processFiles.php
<?
$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 sucessfully!<br>";
 }else{
 echo "$file_name | could not be uploaded!<br>";
 }
} // end of loop
?>

EDITED BY thorpe: Added a more approprate title.

#2 Mr_Pancakes

Mr_Pancakes
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSouthwest USA

Posted 20 September 2006 - 05:06 AM

in your processFiles.php, try adding the pre-existing folder name to where your upload will be placed.

$copy = copy($folder_location . $_FILES['uploadFile'. $x]['tmp_name'],$file_name);


where, $folder_location is already existing. if you need to create the folder right then, you can use the mkdir() function.

cheers.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users