我有以下代码,我想上传四个文件并重命名它们......我怎么能按照我的代码去处理它。代码工作但是返回这个.file存在接受四个参数,帮帮我很好地完成它
<?php
require'../php/connection.php';
$AdDesPrice="";
$AdDescription="";
$AdTitle="";
$ItemTitle='';
$DescAd='';
$AdPrice='';
$AdSubcategory='';
$Adcategory='';
$fileName1 = '';
$fileName2 = '';
$fileName3 = '';
$fileName4 = '';
if(isset($_POST['bisnaId'],$_POST['Category'],$_POST['ItemTitle'],$_FILES['AdImage1']['name'],$_FILES['AdImage2']['name'],$_FILES['AdImage3']['name'],$_FILES['AdImage4']['name'],$_POST['DescAd'],$_POST['AdPrice'],
$_POST['MobilePhones'],$_POST['ComputerDesigns'],$_POST['Vehicles'],$_POST['Electronics'],$_POST['BeautyCare'],$_POST['MakeUpCosmetics'],$_POST['PersonalGrooming'],$_POST['ladysFashion'],$_POST['MenFAshion'],$_POST['KidsClothing']
,$_POST['HairCare'],$_POST['AnimalsandPets'],$_POST['RealEstate'],$_POST['FoodsBeverages'],$_POST['HobbiesSport'],$_POST['HomeFurniture'],$_POST['LadysAccessories'],$_POST['MensAccessories'],$_POST['FootWear'],$_POST['OralCare'],$_POST['Entertainment'],$_POST['Films']
,$_POST['MusicalInstruments'],$_POST['AgriculturalEquipments'],$_POST['ServicesJobs'])){
$bisnaId=$_POST['bisnaId'];
$Category=$_POST['Category'];
$AdImage1=$_FILES['AdImage1']['name'];
$AdImage2=$_FILES['AdImage2']['name'];
$AdImage3=$_FILES['AdImage3']['name'];
$AdImage4=$_FILES['AdImage4']['name'];
$ItemTitle=htmlentities(mysql_real_escape_string($_POST['ItemTitle']));
$DescAd=htmlentities(mysql_real_escape_string($_POST['DescAd']));
$AdPrice=htmlentities(mysql_real_escape_string($_POST['AdPrice']));
$MobilePhones=$_POST['MobilePhones'];
$ComputerDesigns=$_POST['ComputerDesigns'];
$Vehicles=$_POST['Vehicles'];
$Electronics=$_POST['Electronics'];
$BeautyCare=$_POST['BeautyCare'];
$MakeUpCosmetics=$_POST['MakeUpCosmetics'];
$PersonalGrooming=$_POST['PersonalGrooming'];
$ladysFashion=$_POST['ladysFashion'];
$MenFAshion=$_POST['MenFAshion'];
$KidsClothing=$_POST['KidsClothing'];
$HairCare=$_POST['HairCare'];
$AnimalsandPets=$_POST['AnimalsandPets'];
$RealEstate=$_POST['RealEstate'];
$FoodsBeverages=$_POST['FoodsBeverages'];
$HobbiesSport=$_POST['HobbiesSport'];
$HomeFurniture=$_POST['HomeFurniture'];
$LadysAccessories=$_POST['LadysAccessories'];
$MensAccessories=$_POST['MensAccessories'];
$FootWear=$_POST['FootWear'];
$OralCare=$_POST['OralCare'];
$Entertainment=$_POST['Entertainment'];
$Films=$_POST['Films'];
$MusicalInstruments=$_POST['MusicalInstruments'];
$AgriculturalEquipments=$_POST['AgriculturalEquipments'];
$ServicesJobs=$_POST['ServicesJobs'];
$user_id=getUserField('account_id');
if(!empty($Category)){
if(!empty($MobilePhones) || !empty($ComputerDesigns) || !empty($Vehicles) || !empty($Electronics)|| !empty($BeautyCare) ||
!empty($MakeUpCosmetics) || !empty($PersonalGrooming) || !empty($ladysFashion) || !empty($MenFAshion) || !empty($KidsClothing) || !empty($MensFashion)
|| !empty($HairCare) || !empty($AnimalsandPets) || !empty($RealEstate) || !empty($FoodsBeverages) || !empty($HobbiesSport)
|| !empty($HomeFurniture) || !empty($LadysAccessories) || !empty($MensAccessories) || !empty($FootWear)
|| !empty($OralCare) || !empty($Entertainment)|| !empty($Films) || !empty($MusicalInstruments)
|| !empty($AgriculturalEquipments) || !empty($ServicesJobs)){
if($MobilePhones){
$subCategory=$MobilePhones;
}else if($ComputerDesigns){
$subCategory=$ComputerDesigns;
}else if($Vehicles){
$subCategory=$Vehicles;
}else if($Electronics){
$subCategory=$Electronics;
}else if($Electronics){
$subCategory=$Electronics;
}else if($BeautyCare){
$subCategory=$BeautyCare;
}else if($MakeUpCosmetics){
$subCategory=$MakeUpCosmetics;
}else if($PersonalGrooming){
$subCategory=$PersonalGrooming;
}else if($ladysFashion){
$subCategory=$ladysFashion;
}else if($MenFAshion){
$subCategory=$MenFAshion;
}else if($KidsClothing){
$subCategory=$KidsClothing;
}else if($HairCare){
$subCategory=$HairCare;
}else if($AnimalsandPets){
$subCategory=$AnimalsandPets;
}else if($RealEstate){
$subCategory=$RealEstate;
}else if($FoodsBeverages){
$subCategory=$FoodsBeverages;
}else if($HobbiesSport){
$subCategory=$HobbiesSport;
}else if($HomeFurniture){
$subCategory=$HomeFurniture;
}else if($LadysAccessories){
$subCategory=$LadysAccessories;
}else if($MensAccessories){
$subCategory=$MensAccessories;
}else if($FootWear){
$subCategory=$FootWear;
}else if($OralCare){
$subCategory=$OralCare;
}else if($Entertainment){
$subCategory=$Entertainment;
}else if($Films){
$subCategory=$Films;
}else if($MusicalInstruments){
$subCategory=$MusicalInstruments;
}else if($AgriculturalEquipments){
$subCategory=$AgriculturalEquipments;
}else if($ServicesJobs){
$subCategory=$ServicesJobs;
}
$location="BusinessAdsUploads/";
if(!empty($ItemTitle)){
if(!empty($DescAd)){
$extension1=strtolower(substr($AdImage1, strpos($AdImage1, '.') +1));
$extension2=strtolower(substr($AdImage2, strpos($AdImage2, '.') +1));
$extension3=strtolower(substr($AdImage3, strpos($AdImage3, '.') +1));
$extension4=strtolower(substr($AdImage4, strpos($AdImage4, '.') +1));
$fileData1 = pathinfo(basename($_FILES["AdImage1"]["name"]));
$fileData2 = pathinfo(basename($_FILES["AdImage2"]["name"]));
$fileData3 = pathinfo(basename($_FILES["AdImage3"]["name"]));
$fileData4 = pathinfo(basename($_FILES["AdImage4"]["name"]));
if(!empty($AdImage1)){
if($extension1=='png' || $extension1=='gif' || $extension1=='jpeg' || $extension1=='jpg'){
$fileName1 = uniqid() . '.' . $fileData1['extension'];
}
}
if(!empty($AdImage2)){
if($extension2=='png' || $extension2=='gif' || $extension2=='jpeg' || $extension2=='jpg'){
$fileName2 = uniqid() . '.' . $fileData2['extension'];
}
}
if(!empty($AdImage3)){
if($extension3=='png' || $extension3=='gif' || $extension3=='jpeg' || $extension3=='jpg'){
$fileName3 = uniqid() . '.' . $fileData3['extension'];
}
}
if(!empty($AdImage4)){
if($extension4=='png' || $extension4=='gif' || $extension4=='jpeg' || $extension4=='jpg'){
$fileName4 = uniqid() . '.' . $fileData4['extension'];
}
}
$target_path1 = 'BusinessAdsUploads/'. $fileName1;
$target_path2 = 'BusinessAdsUploads/'. $fileName2;
$target_path3 = 'BusinessAdsUploads/'. $fileName3;
$target_path4 = 'BusinessAdsUploads/'. $fileName4;
while(file_exists($target_path1,$target_path2,$target_path3,$target_path4))
{
if(!empty($AdImage1)){
$fileName1 = uniqid() . '.' . $fileData1['extension'];
}
if(!empty($AdImage2)){
$fileName2 = uniqid() . '.' . $fileData2['extension'];
}
if(!empty($AdImage3)){
$fileName3 = uniqid() . '.' . $fileData3['extension'];
}
if(!empty($AdImage4)){
$fileName4 = uniqid() . '.' . $fileData4['extension'];
}
$target_path1 = 'BusinessAdsUploads/'. $fileName1;
$target_path2 = 'BusinessAdsUploads/'. $fileName2;
$target_path3 = 'BusinessAdsUploads/'. $fileName3;
$target_path4 = 'BusinessAdsUploads/'. $fileName4;
}
move_uploaded_file($_FILES['AdImage1']['tmp_name'],$target_path1);
move_uploaded_file($_FILES['AdImage2']['tmp_name'],$target_path2);
move_uploaded_file($_FILES['AdImage3']['tmp_name'],$target_path3);
move_uploaded_file($_FILES['AdImage4']['tmp_name'],$target_path4);
$query="insert into `MyAds` values('','$bisnaId','$user_id','$Category','$subCategory','$fileName1','$fileName2','$fileName3','$fileName4','$ItemTitle','$DescAd','$AdPrice','Personal Business')";
if($query_run=mysql_query($query)){
header('location:PreviewBisnaAd.php');
}
}else{
$AdDescription="<font color=red><i>Describe your Ad</i></font>";
}
}else{
$AdTitle="<font color=red><i>Enter your Ad Title</i></font>";
}
}else{
$AdSubcategory='<font color=red><i>Select Your Ad Sub Category</i></font>';
}
}else{
$Adcategory='<font color=red><i>Select Your Ad Category</i></font>';
}
}
?>
答案 0 :(得分:0)
file_exists
只接受一个参数。将while(file_exists($target_path1,$target_path2,$target_path3,$target_path4))
更改为:
while(file_exists($target_path1) and
file_exists($target_path2) and
file_exists($target_path3) and
file_exists($target_path4))