PHP:如何在这段代码中实现exif_imagetype
请看一下: 现在,我尝试扩展这段代码并添加更多的检查程序,如第139行所示的exif_imagetype() 我不能让它工作,我只是收到exif_imagetype无法打开流,没有这样的。。。(图像不存在)。我还在参数中尝试了$this->file->getName(),但仍然出现了相同的错误 现在我在质疑整件事。在图像到达if($this->file->save..之前,我看不到图像在任何地方被上传。但是它如何检索pathinfo()?为什么['dirname'].'basename']找不到文件?对于dirname,我只得到了一个。但是basename我得到了我正试图上传的正确图像文件名 那么它是如何工作的,我应该在哪里将这个exif_imagetype检查器实现到代码中呢PHP:如何在这段代码中实现exif_imagetype,php,image,types,exif,Php,Image,Types,Exif,请看一下: 现在,我尝试扩展这段代码并添加更多的检查程序,如第139行所示的exif_imagetype() 我不能让它工作,我只是收到exif_imagetype无法打开流,没有这样的。。。(图像不存在)。我还在参数中尝试了$this->file->getName(),但仍然出现了相同的错误 现在我在质疑整件事。在图像到达if($this->file->save..之前,我看不到图像在任何地方被上传。但是它如何检索pathinfo()?为什么['dirname'].'basename']找不到
感谢您转发。这只是XHR案例的一个快速而肮脏的实现(如聊天中所讨论的):
你能发布你用来实现这个类的代码吗?我把它和javascript中的ajax调用请求一起使用。这就是你想要看到的吗?这是一个javascript插件,我只设置了设置以及它应该向哪里发出请求。
/**
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {
protected $_tempFile;
public function __construct() {
$input = fopen("php://input", "r");
$this->_tempFile = tempnam(sys_get_temp_dir(), 'xhr_upload_');
file_put_contents($this->_tempFile, $input);
fclose($input);
}
public function checkImageType() {
switch(exif_imagetype( $this->_tempFile )) {
case IMAGETYPE_GIF:
case IMAGETYPE_JPEG:
case IMAGETYPE_PNG:
return true;
break;
default:
return false;
break;
}
}
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
if (filesize($this->_tempFile) != $this->getSize()){
return false;
}
rename($this->_tempFile, $path);
return true;
}
function getName() {
return $_GET['qqfile'];
}
function getSize() {
if (isset($_SERVER["CONTENT_LENGTH"])){
return (int)$_SERVER["CONTENT_LENGTH"];
} else {
throw new Exception('Getting content length is not supported.');
}
}
}