gpt4 book ai didi

php - 尝试新的文件上传方式

转载 作者:行者123 更新时间:2023-11-29 03:47:06 26 4
gpt4 key购买 nike

所以我决定将文件上传到网络服务器空间而不是 mysql 空间,但每次我尝试上传任何东西时我都会收到以下错误:

    Warning: move_uploaded_file() [function.move-uploaded-file]: Filename cannot be empty in /home/speedycm/public_html/manageclient.php on line 240

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpq7cUA4' to '' in /home/speedycm/public_html/manageclient.php on line 240
Error uploading file

这是我使用的代码:

 <?php
if (array_key_exists('uploadfile',$_POST)) {

$uploadDir = '/upload';

$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$filePath = $uploadDir . $fileName;

// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);

// make the random file name
$randName = md5(rand() * time());

// and now we have the unique file name for the upload file
$filePath = $uploadDir . $randName . '.' . $ext;

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$content = addslashes($filePath);
}

mysql_query("INSERT INTO tbl_accidentfiles (`client_id`,`name`,`type`,`size`,`path`)
VALUES ('$client_id', '$fileName', '$fileType', '$fileSize','$filePath')");

echo '<b>File Upload</b><p>Thank you. The file has been successfully uploaded.

<p><img src="resources/spacer.gif" alt="" width="300px" height="5px" /><p><o>

<i><u>Name:</u>&nbsp;' . $fileName . '<p><i><u>Size:</u>&nbsp;' . $fileSize . 'k' . '<p><u>Type:</u>&nbsp;' . $fileType . '</i><i><u>Path:</u>&nbsp;' . $filePath. '<p><p><p><img src="resources/spacer.gif" alt="" width="300px" height="5px" />';

关于我做错了什么有什么想法吗?

最佳答案

Warning: move_uploaded_file() [function.move-uploaded-file]: Filename cannot be empty in /home/speedycm/public_html/manageclient.php on line 240

这意味着 $_FILES['userfile']['tmp_name'] 中的内容实际上是空的,或者不存在。在 $_FILES 上运行 print_rvar_dump 以查看实际存在的内容。您可能在某处打错了字。

关于php - 尝试新的文件上传方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2360124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com