-2

如何重命名上传的文件str_replace function?我想删除spacewith _。有什么帮助吗?我正在使用以下代码上传文件

$file1 = 'order_'.$orderId.'_'.$rowsOrder['image_a'];
$file2 = 'order_'.$orderId.'_'.$rowsOrder['image_b'];
$file3 = 'order_'.$orderId.'_'.$rowsOrder['image_c'];
$file4 = 'order_'.$orderId.'_'.$rowsOrder['image_d'];
$path1 = 'http://www.yourdomain.com/'.$file1;
$path2 = 'http://www.yourdomain.com/'.$file2;
$path3 = 'http://www.yourdomain.com/'.$file3;
$path4 = 'http://www.yourdomain.com/'.$file4;

      <tr>";
               if($rowsOrder['image_a'] !=''){
                $message.="<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file1."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File1</a></td>";}
                if($rowsOrder['image_b'] !=''){

               $message.= "<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file2."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File2</a> </td>";}


             $message.=  "</tr><tr>";


            if($rowsOrder['image_c'] !=''){
                $message.= "<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file3."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File3</a></td>";}
                if($rowsOrder['image_d'] !=''){
               $message.= "<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file4."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File4</a> </td>";}
               $message.= "</tr><tr>
                        <td colspan='2' align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;font-weight: bolder;'><br><br>Thanks,<br><br>
                          <span style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000; font-weight: normal;'><a href='http://www.yourdomain.com/' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>yourdomain</a></span></td></tr>

$order_image_a='order_'.$orderId.'_'.$filea;
if(!empty($filea)) move_uploaded_file($_FILES['FILE1']['tmp_name'], "../files/$order_image_a");

$order_image_b='order_'.$orderId.'_'.$fileb;
if(!empty($fileb)) move_uploaded_file($_FILES['FILE2']['tmp_name'], "../files/$order_image_b");

$order_image_c='order_'.$orderId.'_'.$filec;
if(!empty($filec)) move_uploaded_file($_FILES['FILE3']['tmp_name'], "../files/$order_image_c");

$order_image_d='order_'.$orderId.'_'.$filed;
if(!empty($filed)) move_uploaded_file($_FILES['FILE4']['tmp_name'], "../files/$order_image_d");

如果我要上传图片或任何名称中有空格的文件,则应使用 _ 代替 gap 上传(例如 -you files.doc应由 上传you_files.doc)。可能的 ?

4

1 回答 1

0
function convertSpecialChars($str) {
    $str = str_replace( " ", "_", $str );
    return $str;
}

$filea = $this->convertSpecialChars($filea);

$order_image_a='order_'.$orderId.'_'.$filea;
if(!empty($filea)) move_uploaded_file($_FILES['FILE1']['tmp_name'], "../files/$order_image_a");
于 2012-12-29T21:51:03.737 回答