小编Lio*_*nby的帖子

重命名文件(如果已存在) - php上传系统

我这个PHP代码:

<?php

// Check for errors
if($_FILES['file_upload']['error'] > 0){
    die('An error ocurred when uploading.');
}

if(!getimagesize($_FILES['file_upload']['tmp_name'])){
    die('Please ensure you are uploading an image.');
}

// Check filesize
if($_FILES['file_upload']['size'] > 500000){
    die('File uploaded exceeds maximum upload size.');
}

// Check if the file exists
if(file_exists('upload/' . $_FILES['file_upload']['name'])){
    die('File with that name already exists.');
}

// Upload file
if(!move_uploaded_file($_FILES['file_upload']['tmp_name'], 'upload/' . $_FILES['file_upload']['name'])){
    die('Error uploading file - check destination is writeable.');
}

die('File uploaded successfully.');

?>
Run Code Online (Sandbox Code Playgroud)

我需要对现有文件采取"窗口"处理方式 - 我的意思是如果文件存在,我希望将其更改为后面带有数字1的文件名.

例如:myfile.jpg已经存在,所以如果你再次上传它将是myfile1.jpg,如果myfile1.jpg存在,它将是myfile11.jpg等等......

我该怎么做?我尝试了一些循环但不幸的是没有成功.

php upload file exists

3
推荐指数
1
解决办法
2万
查看次数

希伯来语编码-PHP,MySQLi

我正在使用MySQLi从数据库中检索信息。我所有的页面都使用UTF-8编码,没有BOM,我有2个页面要处理,但是主要的问题是数据库上的信息以常规方式显示-但是当我检索它时,它是这样的:

?????? ?????? -????

在phpMyAdmin面板上-列为latin1_general_ci(我也尝试将其设置为utf8_general-相同的输出!)。

“ mysql.php”:

<?php
header('Content-type: text/xhtml; charset=windows-1255');
$mysql = new mysqli('localhost', 'elenbyin_vadim', 'pass33323', 'elenbyin_vadim');
?>
Run Code Online (Sandbox Code Playgroud)

“ index.php”,主要部分:

<?php
include ('mysql.php');
include('functions.php');

if($_GET["lang"] == 'rus')
    $lang = 'rus';
else if($_GET["lang"] == 'heb')
    $lang = 'heb';
else
    $lang = 'heb';
Run Code Online (Sandbox Code Playgroud)

......

<div class="main_text">
<?

    $result = $mysql->query('SELECT * FROM homepage');
    while($row = mysqli_fetch_array($result)){
        echo "".$row['title']."<br />".$row['text_heb']."";
    }
?>
</div>
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我解决这个问题吗?

php mysql mysqli

1
推荐指数
1
解决办法
1123
查看次数

标签 统计

php ×2

exists ×1

file ×1

mysql ×1

mysqli ×1

upload ×1