Page 1 of 1

Help with image path

Posted: Tue Sep 14, 2010 10:50 pm
by jonasitos
Hey Everyone, I have these 3 scripts to upload an image but I'm having an issue because the images uploaded are going to the same directory as the pages. What do I need to change to make the uploaded images go to a folder called "pictures". Thanks in advance for the help.

Code: Select all

Script 1

<form name="form1" method="post" action="adminpicturebrowse.php">
<p align="center">How many pictures for this dog? Max is 9</p>
<p align="center">
<input name="uploadNeed" type="text" id="uploadNeed" maxlength="1">
<input type="submit" name="Submit" value="Submit">
</p>
</form>


Script 2

<form name="form1" enctype="multipart/form-data" method="post" action="adminaddupload.php">
<p align="center">
<?
  // 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>
<div align="center">
<?
  // end of for loop
  }
  ?>
</div>
<p align="center"><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
<input type="submit" name="Submit" value="Submit">
</p>
</form>


Script 3

<?
$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<br>";
 }else{
 echo "$file_name<br>";
 }
} // end of loop
?> 

Re: Help with image path

Posted: Wed Sep 15, 2010 12:41 am
by PradeepKr
Replace this

Code: Select all

$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
with this

Code: Select all

$file_name = str_replace("'","",$file_name);
$file_name = 'pictures/'.$file_name;
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
Donot forget to give proper permissions (write) to this folder.