繁体   English   中英

我如何仅将文件名保留为VARCHAR就可以在数据库中上传照片?

[英]How can i upload a photo in a database with just holding on the the file name as a VARCHAR?

因此,我不想将照片存储在数据库中,因为这会占用过多的内存。 我要保留文件名,然后使用该名称访问照片。 我怎样才能做到这一点? 到目前为止,这是我的代码,但是它不起作用。 在这段代码中,我试图将filezilla中的文件夹作为目标文件夹。 现在move_upload_file()返回false,我该怎么做才能使其返回true? 我尚未实现数据库,但是当我执行操作时,如何获取文件名的字符串并访问照片? 我的html:

<form method="post" action="BugReport.php" enctype="multipart/form-data">
                <div style = 'margin: 10px 225px 0px 225px;'><input type="hidden" name="size" value="350000">
                <input type="file" name="photo"> </div>
            </form>

我的PHP:

//This is the directory where images will be saved
$target = "http://TheUrlIWantToUploadTo/Internship_Program/Edward/Project_5/Project_5/Output";
$target = $target . basename( $_FILES['photo']['name']);

$pic=($_FILES['photo']['name']);


//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}

您不能将URL用作move_uploaded_file()的目标。 考虑一下-您刚刚处理了HTTP上传,并尝试将其上传到另一个URL,这将触发另一个HTTP上传。

m_u_l()需要一个本地文件路径,而不是URL。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM