我目前正在做一个Joomla!网站.我正在使用Jumi扩展(允许在Joomla!本身内制作和执行自定义脚本)来创建一个简单的文件上传工具.问题是我收到以下错误:
警告:复制(C:/xampp/htdocs/images/1253889508.jpg)[function.copy]:无法打开流:C:\ xampp\htdocs\Joomla\components\com_jumi\jumi.php中没有此类文件或目录(25):第61行的eval()代码
违规代码如下:
//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname='C:/xampp/htdocs/images/'.$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
Run Code Online (Sandbox Code Playgroud)
完整代码可在此处获得.一旦我开始工作,我将修改它以满足我的网站的需求.
我不确定问题是否是Jumi的权限问题,或者是否存在其他问题.我能说的最好的是,无论出于何种原因,都没有创建临时文件.
感谢您提供的任何提示!
我有一个问题,找出将图像上传到其他目录的相对路径
目标目录
htdocs/dt3/tadi/adm/dim/dim_images/tadi_user_images/
Run Code Online (Sandbox Code Playgroud)
源目录
htdocs/dt3/tadi/adm/cbt/uploadfile.php
Run Code Online (Sandbox Code Playgroud)
<html>
<form method="post"enctype="multipart/form-data">
<input type="file" name="fileimg1" ><input type="submit" name="upload">
</form>
</html>
<?php
$dirname = "/dt3/tadi/adm/dim/dim_images/tadi_user_images/";
$of = $_FILES['fileimg1']['name'];
$ext = pathinfo($of, PATHINFO_EXTENSION);
$changename3 = time() * 24 * 60;
$image_name3 = "timage_" . $changename3 . "." . $ext;
$final_pathdir = $dirname . $image_name3;
$suc = move_uploaded_file($_FILES['fileimg1']['tmp_name'], $final_pathdir);
if ($suc > 0)
{
echo "Image uploaded successfully";
}
else
{
echo "Error : " . $_FILES['filimg1']['error'];
}
?>
Run Code Online (Sandbox Code Playgroud)
我尝试了一些路径,我没有得到任何解决方案.
如何将图像上传到该路径?
htdocs/dt3/tadi/adm/dim/dim_images/tadi_user_images/
只有相对路径.
我正在使用twitter bootstrap版本2.3.2处理表单,表单没有任何标签,每个输入字段都使用占位符.表单上的所有输入字段都显示除文件上载之外的占位符文本.
我试过添加,<input class="input-xxlarge" type="file" name="service_guide"
placeholder="Upload image"/>但似乎没有用.
这是fileupload的HTML
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="input-append">
<div class="uneditable-input span3">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"></span>
</div>
<span class="btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change</span>
<input class="input-xxlarge" type="file" name="service_guide"
placeholder="Upload image"/>
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这就是我的表格

我真的很感激这里的任何帮助.
我正在尝试上传并在ng-repeat中显示图像.
我已成功使用jquery函数上传和显示没有ng-repeat的图像:
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
</head>
<body>
<input type='file' />
<img id="myImg" ng-src="#" alt="your image" style="width:50px;height:50px"/>
</body>
</html>
...
<script>
$(function () {
$(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
$('#myImg').attr('src', e.target.result);
};
</script>
Run Code Online (Sandbox Code Playgroud)
如果我将代码更改为ng-repeat内部,则jQuery函数可以正常工作:
<div ng-repeat="step in stepsModel">
<input type='file' />
<img id="myImg" ng-src="#" alt="your image" style="width:50px;height:50px"/>
/div>
Run Code Online (Sandbox Code Playgroud)
2个问题:
非常感谢
我目前正在学习django,我正在尝试创建一个简单的上传站点。我想我应该django FileField用于此目的,但我想知道如何使用 django 模板在索引页面上显示使用此字段上传的图像。我知道我可以ImageField在我的情况下使用 ,但我想知道是否可以使用FileField?
我正在创建一个表单,允许用户选择图像并使用 Django 和 AJAX 上传它。这个过程工作正常,但问题是上传的图像没有显示在屏幕上,但我确实div为其指定了一个。
这些是我遵循的步骤:
模型.py:
class photo(models.Model):
title = models.CharField(max_length=100)
img = models.ImageField(upload_to = 'img/')
Run Code Online (Sandbox Code Playgroud)
主页.html:
<form method="POST" id="ajax" enctype="multipart/form-data">
{% csrf_token %}
Img:
<br />
<input type="file" name="img">
<br />
<br />
<button id="submit" type="submit">Add</button>
</form>
<h1> test </h1>
<div id="photo">
<h2> {{ photo.title }}</h2>
<img src="{{ photo.img.url }}" alt="{{ photo.title }}">
</div>
$('#ajax').submit(function(e) {
e.preventDefault();
var data = new FormData($('#ajax').get(0));
console.log(data)
$.ajax({
url: '/upload/',
type: 'POST',
data: data, …Run Code Online (Sandbox Code Playgroud) 我只需要上传图像的输入,我尝试使用此代码,但如果我从上传窗口中选择所有文件,我仍然可以使用一些 .exe 文件,它只是发出警报,我可以按确定,然后文件仍然上传和我可以按提交。
如何删除上传的文件??
function validateFileType(){
var fileName = document.getElementById("fileName").value,
idxDot = fileName.lastIndexOf(".") + 1,
extFile = fileName.substr(idxDot, fileName.length).toLowerCase();
if (extFile=="jpg" || extFile=="jpeg" || extFile=="png"){
//TO DO
}else{
alert("Only jpg/jpeg and png files are allowed!");
}
}Run Code Online (Sandbox Code Playgroud)
<input name="image" type="file" id="fileName" accept=".jpg,.jpeg,.png" onchange="validateFileType()">Run Code Online (Sandbox Code Playgroud)
我正在尝试使用代码点火器框架上传图像,因为我的控制器类代码如下
public function addNewSlider()
{
if($this->session->userdata('logged_in'))
{
$this->form_validation->set_rules('title','Title','required');
if($this->form_validation->run()===FALSE)
{
$data['content']=$this->input->get_post('content');
$data['file']=$this->input->get_post('file');
$data['status']=$this->input->get_post('status');
$this->load->view('admin/templates/header',array('sessionArray'=>$this->sessionArray));
$this->load->view('admin/sliders/addNewSlider',$data);
$this->load->view('admin/templates/footer');
}
else
{
/*$title=$this->input->get_post('title');
$content=$this->input->get_post('content');
$image=$this->input->get_post('file');
$status=$this->input->get_post('status');
$this->sliders_model->insertNewMenu($title,$content,$image,$status);
redirect('sliders','refresh');*/
}
}
else
{
redirect('index','refresh');
}
}
function do_upload()
{
$name=time();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
// $config['max_size'] = '100';
// $config['max_width'] = '1024';
//$config['max_height'] = '768';
$config['file_name']=$name;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
print_r($error);exit;
//$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
//$this->load->view('upload_success', $data);
} …Run Code Online (Sandbox Code Playgroud)