【发布时间】:2014-07-22 13:18:54
【问题描述】:
我正在使用 PHP 为 FileMaker 数据库创建一个网站。我要做的是上传一个图像文件,以便数据库可以访问它。
这是我的代码(来自教程):
if (isset($_POST['action']) and $_POST['action'] == 'Upload') {
# set the destination directory for the image
$image_directory = 'http://mydomain.com/Images/My_Example/';
# set the temp and dest file names with paths
$temporary_file = $_FILES['new_image']['tmp_name'];
$destination_file = $image_directory . $_FILES['new_image']['name'];
# move file to the images directory
$result = move_uploaded_file($temporary_file, $destination_file);
if ($result) {
# insert the URL into the product record
$edit = $fm->newEditCommand('Product', $_REQUEST['recid']);
$edit->setField('Thumbnail URL', $destination_file);
$edit->execute();
} else {
$error_message = nl2br("temporary_file = ".$temporary_file."\n");
$error_message.= nl2br("destination_file = ".$destination_file."\n\n");
echo $error_message;
die('There was an error moving the file.');
}
}
我知道函数“move_uploaded_file()”会移动临时文件,但我看不到实际上首先上传到临时文件的语句。请问我错过了什么? (不知道这算不算红鲱鱼!)
但是“move_uploaded_file()”失败了,我收到了错误消息(我添加了它以尝试调试它)和“死”消息。有什么方法可以得到错误代码,告诉我为什么它失败了?
我确信相关目录确实具有读/写权限。而 'mydomain.com' 实际上在脚本中被替换为真实的域。
感谢您的任何建议。我是PHP的新手,所以在回答时请记住这一点!非常感谢。
干杯
【问题讨论】:
-
您要上传的文件夹的所有者是谁?
-
如果这就是你的全部,我认为你是对的,实际上保存临时文件的代码丢失了。
-
您不必提供完整路径。您的上传路径应从网络根目录开始
-
该文件夹是否可以通过网络访问
标签: php image upload image-uploading