2016-04-08 9 views
0

は、どのように私は配列でなければなりませんセッション

<?php 
 
lets have a look in my code i am uploading multiple images using form action 
 
here i am uploading multiple images 
 
Session_Start(); 
 
if (isset($_POST['submit'])) { 
 
    $j = 0; //Variable for indexing uploaded image 
 
    
 

 

 
    $upload_path = "/var/www/html/addtocart/"; //Declaring Path for uploaded images 
 
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array 
 

 
          $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed 
 
          $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) 
 
          $file_extension = end($ext); //store extensions in the variable 
 
          $target_path = $upload_path . basename($_FILES["file"]["name"][$i]);//set the target path with a new name of image 
 
      
 
    
 

 
         $j = $j + 1;//increment the number of uploaded images according to the files in array  
 
if (file_exists($target_path)) { 
 
    echo "Sorry, file already exists."; 
 
    $uploadOk = 0; 
 
}  
 

 
else { 
 
if(($_FILES["file"]["size"][$i] <50000000) //Approx. 100kb files can be uploaded. 
 
       && in_array($file_extension, $validextensions)) 
 
{ 
 

 
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder 
 
       echo $j.') .<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; 
 
       
 
$File_Name= basename($_FILES["file"]["name"][$i]); 
 
    echo $File_Name. "</br>"; 
 

 
     
 
    
 
$var_holding_img = "<img src='$File_Name' alt='picture' width='200' height='256'><br/>"; 
 
$string = $var_holding_img ; //here i want to store multiple images and show all the images in another page 
 
$_SESSION['File_Name'] = $string; 
 
echo $_SESSION['File_Name'] ; 
 
    
 

 

 

 

 

 

 
      } else {//if file was not moved. 
 
       echo $j. ').<span id="error">please try again!.</span><br/><br/>'; 
 
      } 
 
     } else {//if file size and file type was incorrect. 
 
      echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; 
 
     } 
 

 
} 
 
    
 

 
    } 
 

 
echo '<script type="text/javascript">   
 
     
 
function Link1()  
 
{  
 
if(document.Form1.checkbox1.checked == true)  
 
{  
 
alert("Want to Add Some More Medicines."); 
 
location.href="products.php"; 
 
}  
 
}  
 
function Link2()  
 
{  
 
if(document.Form1.checkbox2.checked == true)  
 
{  
 
alert("You have clicked on Make Delivery At Home."); 
 
location.href="billing.php";  
 
}  
 
} 
 
     
 
</script>'; 
 

 

 
    
 

 
echo "<form name='Form1' style='color: green ; font-size: 150%' action = '#'> 
 
<input type='radio' name='checkbox1' value='' onclick = 'Link1()' />Want to Add Some More Medicines<br> 
 
<input type='radio' name='checkbox2' value='' onclick = 'Link2()' />Make Delivery At Home<br> 
 
</form>"; 
 

 

 

 
}

+0

このコードで私を助けてください –

+1

あなたは両方のページでセッションを開始しましたか? –

+0

はい私は両方のページでseesionを開始しました –

答えて

0
  1. $_SESSION['File_Name']を使用して別のページに複数の画像を表示します。
  2. 両方のページでsession_start();が必要です。私は知りません :
  3. あなたが表示されるまで、あなたの結果のためにあなたが望むようにループ内でトラフ配列を反復処理し、HTMLを生成する必要がある2番目のページ上のすべての画像を表示するには...

あなたのコードからあなたの画像のリンクを取得する方法(DBからまたはJSの最初のページからそれらをスクラップするか、ファイルから取得するかトラフのディレクトリから...)次のようなことをしてください:

$imgSrcArray = $_SESSION['fileNames']; 
echo '<ul>'; 
foreach ($imgSrcArray as $src) { 
    echo '<li><img src="'.$src.'"/></li>'; 
} 
echo '</ul>'; 

もちろん、htmlに合わせて調整してください。

第二編集:その後、http://php.net/manual/en/function.scandir.phpとあなたの画像のファイル名とのセッションの配列を移入: 確認し、この1。上記のようなコードを上記のように変更してくださいecho '<li><img src=HERE_GOES_PATH_TO_YOUR_FOLDER/"'.$src.'"/></li>';

+0

私は例thankoyuで私を説明することができます –

+0

@RohitJha、私は私の答えを編集しました。それがあなたを助けることを願ってください。 –

+0

ここでうまくいきません。私は私のページ全体をアップロードしています。plzeは一見を持っています –

関連する問題