help me with PHP!!

Post everything else here

Moderators: Website/Forum Admins, Other/Off Topic Moderators

gausie
Posts: 1
Joined: Thu Apr 15, 2004 8:18 am

help me with PHP!!

Postby gausie » Thu Apr 15, 2004 8:33 am

I'm trying to make an upload script for my website. It starts with a form asking how many uploads, then PHP handles that and sends them off to my server. Now thats all fine, but I want the files to be renamed so that they have a 'Collection Name' infront of them, that the user types in.

Here are the scripts (this one works, but it may be that the problem with the next one is to do wid this one!!)


<form name="form1" enctype="multipart/form-data" method="post" action="./processFiles.php">
<p align="left"> <font size="2 pt" face="courier new"><strong>Collection Name:
</strong></font>
<input name="uploadName" type="text" id="uploadName" >
</p>
<p align="left">
<?
// 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
}
?>
<p align="left">
<p align="left">
<input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
<p align="left">
<input type="submit" name="Submit" value= "Submit">
</p>
</form>...

Here is the problem one

<?
$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$group_name = $_FILES['uploadName']['group'];
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
new_name = $group_name $file_name
rename = (file_name, new_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
?>
I'm sexy and single.... ok, just single
User avatar
munky
Site Admin
Posts: 826
Joined: Wed Jul 02, 2003 4:54 pm
Location: Phoenix AZ
Contact:

Re: help me with PHP!!

Postby munky » Thu Apr 15, 2004 12:32 pm

ok, i'll take a guess..
<?
$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$group_name = $_POST['uploadName'];
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$new_name = $group_name . $file_name;
//rename = (file_name, new_name); // this would be rename() anyways, not rename=()
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$new_name); // you may want a base path here, ie "~myuser/upload/".$new_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
?>
this is completely untested, use at your own risk
In God we trust,
Everyone else must have an X.509 certificate.

Who is online

Users browsing this forum: No registered users and 8 guests