图像上传与PHP错误?

时间:2017-05-24 11:46:13

标签: php

我只是想在php中创建一个简单的图像上传功能,但出于某种原因它不会使用move_uploaded_file()移动图像。 如果重要的话,我正在通过XAMPP工作。 我也试过设置upload_tmp_dir

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

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 );

错误:

Warning: move_uploaded_file(/uploads/images/1495626347.psd): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/action.php on line 20

Warning: move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/phpYsJkjq' to '/uploads/images/1495626347.psd' in /Applications/XAMPP/xamppfiles/htdocs/action.php on line 20

第20行是:if(!move_uploaded_file($temp_filename, $target_file))

0 个答案:

没有答案