I'm using PHP to create a website for a FileMaker database. What I want to do is upload an image file so it can be accessed by the database.
This is the code I have (which came from a tutorial):
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.');
}
}
I understand that the function 'move_uploaded_file()' will move the temporary file, but I can't see a statement that actually uploads to the temporary file in the first place. What am I missing, please? (I don't know if this is a red herring!)
But 'move_uploaded_file()' fails, and I get the error message (which I added to try to debug it) and the 'die' message. Is there any way to get an error code, to tell me why it failed?
I'm assured that the relevant directory does have read/write access. And 'mydomain.com' is actually replaced by the real domain in the script.
Any advice gratefully received. I'm a newbie to PHP, so please bear that in mind when answering! Many thanks.
Cheers