Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解决文件存在的问题_Php - Fatal编程技术网

Php 如何解决文件存在的问题

Php 如何解决文件存在的问题,php,Php,我有以下代码,我想上传四个文件并重命名它们。。。如何按照我的代码进行操作。代码正在运行,但正在返回此文件。文件exist接受四个参数,请帮助我很好地处理它 <?php require'../php/connection.php'; $AdDesPrice=""; $AdDescription=""; $AdTitle=""; $ItemTitle=''; $DescAd='';

我有以下代码,我想上传四个文件并重命名它们。。。如何按照我的代码进行操作。代码正在运行,但正在返回此文件。文件exist接受四个参数,请帮助我很好地处理它

 <?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>';
            }
            }
    ?>

文件\u存在
只接受一个参数。将(文件\u存在($target\u path1、$target\u path2、$target\u path3、$target\u path4))更改为

while(file_exists($target_path1) and
file_exists($target_path2) and
file_exists($target_path3) and
file_exists($target_path4))

文件\u存在
只接受一个参数。将(文件\u存在($target\u path1、$target\u path2、$target\u path3、$target\u path4))更改为

while(file_exists($target_path1) and
file_exists($target_path2) and
file_exists($target_path3) and
file_exists($target_path4))

如果可以,你应该这样做。它们不再得到维护,而是在使用。学习替代,并考虑使用PDO,哦,谢谢。目前我有一个实时网站,im n担心错误。。。我需要解决它并将代码更改为PDO。。如果你能帮忙,请帮忙…你也只是假设上传总是成功的,永远不会失败。那是个非常糟糕的主意。由于某种原因,$\u文件中有一个
['error']
参数…
while()
将在文件不存在时失败。小心点,如果可以的话,你应该这样做。它们不再得到维护,而是在使用。学习替代,并考虑使用PDO,哦,谢谢。目前我有一个实时网站,im n担心错误。。。我需要解决它并将代码更改为PDO。。如果你能帮忙,请帮忙…你也只是假设上传总是成功的,永远不会失败。那是个非常糟糕的主意。由于某种原因,$\u文件中有一个
['error']
参数…
while()
将在文件不存在时失败。请小心。如果文件不存在,个人使用
while
将失败。最好先传递一个
if()
,然后在需要时执行一段时间。谢谢,它正在工作。。。原谅我不明白你的意思,请个人使用
,如果文件不存在,
将失败。最好先传递一个
if()
,然后在需要时执行一段时间。谢谢,它正在工作。。。原谅我不明白你的意思,请给我进一步说明