- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我正在尝试将图像上传到我的数据库和文件夹以及我表单中的其他元素,一切正常,但我无法让文件出现在上传文件夹中。这是我的代码:
if(isset($_POST['submit'])){
//This gets all the other information from the form
$name = $_POST['name'];
$description = $_POST['description'];
$founded = $_POST['founded'];
$category = $_POST['category'];
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$uploaded_dir = "/httpdocs/uploads/";
$path = $uploaded_dir . $fileName;
print "Temporary name: " . $_FILES['userfile']['tmp_name'] . "<br>";
print "Original name: $filename<br>";
print "Destination: $path<br>";
if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $path)) {
print "Uploaded file moved";
// do something with the file here
} else {
print "Move failed";
}
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()){
$fileName = addslashes($fileName);
}
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("my_db") or die(mysql_error()) ;
//Writes the information to the database
$query = "INSERT INTO mytable (name, description, founded, category, logo)".
"VALUES ('$name', '$description', '$founded', '$category', '$fileName')";
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
echo "<br>File $fileName uploaded<br>";
}
这是我每次得到的回应
Temporary name: /tmp/phpA8JjRz
Original name:
Destination: /httpdocs/uploads/fixed.png
Move failed
File fixed.png uploaded
这是我的表格
<form method="POST" action="path" enctype="multipart/form-data">
<label>Flying School</label><br />
<input type="text" name="name" id="fsn" placeholder="Flying School Name" required/><br />
<label>Category</label><br />
<select name="category">
<option value="0">one</option>
<option value="1">two</option>
<option value="2">three</option>
<option value="3">four</option>
</select><br />
<label>Founded</label><br />
<input type="text" name="founded" id="founded" placeholder="yyyy-mm-dd" /><br />
<label>Logo</label><br />
<!--<div class="uploadlogo">-->
<input type="file" name="userfile" />
<!--</div>--><br />
<label>Cover Image</label><br />
<div class="coverimage">
<input type="file" name="cover" id="cover" />
</div><br />
<label>Description</label><br />
<?php
if (isset($_POST['description'])) $initialentry=$_POST['description'];
else $initialentry='';
$editor = JFactory::getEditor();
echo $editor->display( 'description', $initialentry, '80%', '350', '55', '20', false ) ;
?><br />
<label>Photos</label><br />
<ul id="addPhotos">
<li><div class="upload1">
<input type="file" name="acimg1" id="acimg1" />
</div></li>
<li><div class="upload2">
<input type="file" name="acimg2" id="acimg2" />
</div></li>
<li><div class="upload3">
<input type="file" name="acimg3" id="acimg3" />
</div></li>
</ul>
<br />
<label>Choose here</label><br />
<label class="checkbox-inline">
<input type="checkbox" value="Rss">R22
</label>
<label class="checkbox-inline">
<input type="checkbox" value="R44">R44
</label>
<label class="checkbox-inline">
<input type="checkbox" value="R66">R66
</label>
<label class="checkbox-inline">
<input type="checkbox" value="AS355">AS355
</label>
<label class="checkbox-inline">
<input type="checkbox" value="PA28">PA28
</label>
<label class="checkbox-inline">
<input type="checkbox" value="CESSNA172">Cessna 172
</label>
<label class="checkbox-inline">
<input type="checkbox" value="CESSNA152">Cessna 152
</label><br />
<input class="btn btn-primary" type="submit" name="submit" value="Submit" />
提前致谢!
最佳答案
"SOLVED!!! thanks man I got the true path for the folder and its worked like a dream!! you my friend are a life saver! – Dave Lynch"
将我的评论添加到答案中:
/httpdocs/uploads/
应该是一个完整的系统路径。
即:/var/usr/httpdocs/uploads/
或相对路径。即:../uploads/
。
我怀疑你的根是/httpdocs/
。在大多数服务器上,系统路径通常以 /var/usr/
开头。其他人有类似 /var/usr/public_html/
等。还有更多,但这些已经足够了。
使用 phpinfo()
将显示您的系统路径。
也如评论中所述:
您现在的密码是开放给SQL injection .使用 prepared statements , 或 PDO与 prepared statements .
关于php - move_uploaded_file 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38088114/
脚本: Image uploaded successfully!.'; } else {//if file was not moved. ech
我正在网站上工作,希望用户能够上传文件。所以我正在尝试学习如何做到这一点。经过研究,它说我必须使用函数move_uploaded_file()。我写的代码与示例中的代码一样(更改数据),但是无法正常工
这是我的表格 Admin's Area sponseres list +Add new Sponser &nb
我有一个免费托管网站 - 000webhost.com,它允许您上传图片。 但是,当我尝试上传图片时,出现以下错误: 警告:move_uploaded_file(images/SmallSmileyF
我有一个免费托管网站 - 000webhost.com,它允许您上传图片。 但是,当我尝试上传图片时,出现以下错误: 警告:move_uploaded_file(images/SmallSmileyF
我正在使用带有 mysql 的 wamp 服务器并添加了以下代码 但它没有将文件插入数据库它在数据库中创建名称,在 wamp 文件夹中创建 tmp 文件,但没有将其移动到所需目录 看代码
大家。我在让 PHP 将文件移动到目录中时遇到问题。 mkdir 在创建目录时工作得很好,并且 mysql 表正在插入所有文件。不过,move_uploaded_file 步骤无法正常工作。
我的代码可以成功上传图像。但问题是它无法显示上传的图像。我检查了 html 源 View 中的图像路径输出是否正确,但图像直到不显示。我认为这是一个文件权限问题。我如何上传这些具有读写完全权限的图像,
我正在尝试创建图像 uploader ,但在将图像保存到文件夹中时遇到问题。该文件夹应该位于名为 images 的目录的根目录中吗?如果是这样,当我使用 move_uploaded_file 代码时,
我正在尝试将文件上传到图像文件夹,并将目录路径插入 mysql 数据库。 这是我的 HTML 表单 New Facility ...
我目前有以下内容: if (in_array($_FILES['userfile']['type'], $mimeTypes)) { $target_path = "./uploa
我正在尝试动态上传图片。 HTML 代码是: Select Picture " name="pic"> After I write the following
我正在将我的网站从共享主机迁移到 VPS。在我的 VPS 上进行测试时,我发现突然间我无法再通过网络表单上传文件了。 错误:警告:move_uploaded_file(/uploads/logokle
在 LEMP(Linux CentOS、Nginx、MariaDB、PHP)服务器上,/etc/php.ini 文件具有以下内容。 file_uploads = on upload_tmp_dir =
我一直在编写一个 php 脚本,它创建一个文件夹并将发布的图像保存在创建的文件夹中,文件夹被创建,但图像我没有保存。 下面是脚本: if (isset($_FILES['images'])) {
您好,我正在尝试将图像上传到我的数据库和文件夹以及我表单中的其他元素,一切正常,但我无法让文件出现在上传文件夹中。这是我的代码: if(isset($_POST['submit'])){ //
我正在尝试上传文件,但我的浏览器出现以下错误: Warning move_uploaded_file(public/upload/udesignwptheme138.zip) [function.m
我正在使用下面的脚本,因此用户可以上传他们的个人资料图片。第一次上传图像时(当该位置不存在图像时)效果很好。但是,如果图像已经存在于路径中(如果用户尝试更改个人资料图片),新图像将不会替换旧图像。我确
快速提问 我正在尝试将上传的文件移动到根目录之外的/opt/ffencoderd/data/media 目录,但我得到文件不存在。如果我在同一文件中使用 exec() 在/usr/bin/clamsc
我有 PHP 脚本 (testupload.php): "; if(move_uploaded_file($_FILES['frag3']['name'], $target_path)) {
我是一名优秀的程序员,十分优秀!