2014-09-03 42 views
0

我試圖在上傳過程中重命名一個圖像我知道我遇到把函數rand()和end()但我只是不知道把它放在哪裏是我的代碼如下在上傳過程中重命名一個圖像在php

的PHP/HTML部分

if (isset($_POST['uploadimage'])) { 
    list($typed) = $_FILES['images']['type']; 
    if(!ereg("image",$typed)){ 
    echo "<div class='msg1'>File is not an image or field is empty</div>"; 
     }else{ 
      $pixsname = $_FILES['images']['name']; 
      while(list($key,$value) = each($_FILES['images']['name'])){ 

if(!empty($value)) { 
$pixsname = $value; 
$add = "./img/venues/$pixsname"; 

      copy($_FILES['images']['tmp_name'][$key], $add); 
chmod("$add",0777); 
      } 
       $image = new Image(); 
       $image->load("$add"); 
       $image->resize(652,300); 
       $image->save("$add"); 
} 

echo "<div class='msg1'>Image profile has been updated</div>"; 
     } 
} 



form method="post" enctype="multipart/form-data" id="loginform" > 
<input type="hidden" name="MAX_FILE_SIZE" value="200000000"> 
<input type="file" name="images[]" id="fileField" class="field_ss"/> 
<?php echo $pix; ?> 
<input type="submit" name="uploadimage" value="Upload Image"/> 
</form> 
+1

請閱讀http://php.net/manual/en/features.file-upload.post-method.php – Mir 2014-09-03 09:29:20

回答

0

替換

$pixsname = $value; 

$pixsname = 'The_New_Name_Of_Your_Picture'; 
+0

我建議你再讀一遍他的問題:「..但我只是不知道在哪裏把它放在這裏就是我的代碼「。我想我告訴他究竟該把它放在哪裏。爲什麼這麼討厭呢,爲什麼? – 2014-09-03 10:17:24

+0

我做了這個$ pixsname = rand(1,99999)。 '' .END($值);它上傳圖像,重命名它,但圖像不顯示我注意到圖像中缺少.jpg – 2014-09-03 11:50:20

+0

哦,當然,我的壞。您需要將文件擴展名添加到圖像的名稱。如果你只使用一個文件類型,就像這樣'$ pixsname = rand(1,99999)。 '.jpg';'或者什麼是你的文件類型而不是'.jpg'。如果你使用多種文件類型,你可以這樣做:$ pixsname = rand(1,99999).strrchr($ value,「。」);' – 2014-09-03 12:00:29