图像上传但没有添加到数据库?

时间:2017-05-24 13:19:15

标签: php xampp

我只是想在php中创建一个简单的图像上传功能,但由于某种原因它不会完成任务。它被卡在白色屏幕上,网址为*/action.php,有时我在该页面上收到错误,有时我什么都没得到(截至目前)。
如果重要的话,我正在通过XAMPP工作。

(我知道缺乏准备好的陈述)

action.php的

$target_directory = "/Applications/XAMPP/xamppfiles/htdocs/uploads/";
$filename = $_POST['fileLocation'];
$temp_filename = $_FILES["file"]["tmp_name"];
$size = $_FILES["file"]["size"];

    // Produce a unique filename
$randomNumber = time();
$filetype = substr($filename, strrpos($filename, '.'));
$target_file = $target_directory . $randomNumber . $filetype;
$local_path = "/Applications/XAMPP/xamppfiles/htdocs/uploads/" . $randomNumber . $filetype;

header('Content-type: text/html; charset=utf-8');
if(!move_uploaded_file($temp_filename, $target_file))
        header( 'localhost/index.php', 301 );

// = = = = Add to database = = = =
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("gps");

// Collect data from form
$imagetext = $_POST["imagetext"];
$locationstring = $_POST["locationstring"];


$query = "INSERT INTO gps (imagetext, file, locationstring) VALUES ('$imagetext', '$local_path','$locationstring')";
mysql_query($query);
mysql_close();
        header( 'localhost/index.php', 301 );

错误正在切换:

  

警告:move_uploaded_file(/uploads/images/1495626347.psd):无法打开流:第20行/Applications/XAMPP/xamppfiles/htdocs/action.php中没有此类文件或目录

+

  

警告:move_uploaded_file():无法在/Applications/XAMPP/xamppfiles/htdocs/action.php中将'/ Applications / XAMPP / xamppfiles / temp / phpYsJkjq'移动到'/uploads/images/1495626347.psd' 20

  

警告:文件上传错误 - 无法在第0行的“未知”中创建临时文件

但是,文件应该在本地。

HTML(如果有人想看看):

<form method="POST" action="action.php" enctype="multipart/form-data">

<input id="fileLocation" name="fileLocation" type="text" class="form-control" placeholder="Image to upload" style="display:none">


<button type="button" value="Browse..." id="browseBtn" class="title">Select files...</button>
        <input type="hidden" name="locationstring" style="display:none;"/>
        <input type="file" name="file" id="hiddenFile" style="display: none;"/>
        <input id="content" name="imagetext" class="form-control" type="text" placeholder="Text Below Image"/>
        <input type="submit" value="Upload" name="submit">
</form>

0 个答案:

没有答案