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
?>
help me with PHP!!
Moderators: Website/Forum Admins, Other/Off Topic Moderators
help me with PHP!!
I'm sexy and single.... ok, just single
Re: help me with PHP!!
ok, i'll take a guess..
this is completely untested, use at your own risk<?
$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
?>
In God we trust,
Everyone else must have an X.509 certificate.
Everyone else must have an X.509 certificate.
Who is online
Users browsing this forum: No registered users and 1 guest