简体   繁体   English

文件上传不适用于PHP

[英]File upload Not Working with PHP

So I have a form that allows a user to upload files. 因此,我有一个允许用户上传文件的表单。 When they submit the file, I can get the file information such as name and tmp_name , yet the actually upload doesn't work. 当他们提交文件时,我可以获取文件信息,例如nametmp_name ,但实际上传不起作用。 I don't get any PHP errors either. 我也没有任何PHP错误。 Below is my code, I think I just need another pair of eyes on it, as it was working a few days ago. 下面是我的代码,我想我只需要再看一眼,就像几天前一样。

//Get the file name
$target_Dir = "temp/";

$tempName = $_FILES['file']['tmp_name'];

$target_file = $target_Dir . basename($_FILES["file"]["name"]);

$filename = pathinfo($target_file, PATHINFO_FILENAME);

//Get the password
$password = $_POST['password'];
//Store if the user wants the certificate to remain password protected
$passProtect = $_POST['passProtect'];
//upload the file to the server
move_uploaded_file($tempName, $target_file);

I need the file name without the extension for a later point in my code, in case you're wondering why I'm storing the file name without the extension. 如果您想知道为什么我要存储不带扩展名的文件名,则在代码中稍后需要使用不带扩展名的文件名。

I think you just did this mistake 我想你只是犯了这个错误

$fileExtension = pathinfo($target_file, PATHINFO_FILENAME);

Try using this insted of that Code then only you will get the file name not the extention. 尝试使用该代码的此插入内容,那么只有您将获得文件名而不是扩展名。

I had an unlink() further down in my script for some reason that I can't remember. 由于不记得的原因,我的脚本中还有一个unlink() It deleted the file that the user would upload right away. 它删除了用户立即上传的文件。

Thanks for the extra set of eyes guys. 感谢您提供的额外的支持。

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

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