PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
My first use of ajax for a simple file upload it all worked until I tried to add the last part of showing the uploaded file
I get this error
Parse error: parse error, unexpected '[', expecting ']' in /home/myspace/public_html/featuredimageupload.php on line 13
<?php
/**
* This file uploads a file in the back end, without refreshing the page
*
*/
if (isset($_POST['id'])) {
if (!copy($_FILES[$_POST['id']]['tmp_name'], 'featured/uploads/'.$_FILES[$_POST['id']]['name'])) {
echo '<script> alert("Failed to upload file");</script>';
}
}
else {
echo "Picture uploaded <img scr=\"featured/uploads/'.$_FILES[$_POST['id']]['name']\" width=\"100\">";
}
?>
<?php
/**
* This file uploads a file in the back end, without refreshing the page
*
*/
if (isset($_POST['id'])) {
if (!copy($_FILES[$_POST['id']]['tmp_name'], 'featured/uploads/'.$_FILES[$_POST['id']]['name'])) {
echo '<script> alert("Failed to upload file");</script>';
}
}
else {
echo 'Picture uploaded <img scr="featured/uploads/' . $_FILES[$_POST['id']]['name'] . ' width="100">';
?>
<?php
/**
* This file uploads a file in the back end, without refreshing the page
*
*/
if (isset($_POST['id'])) {
if (!copy($_FILES[$_POST['id']]['tmp_name'], 'featured/uploads/'.$_FILES[$_POST['id']]['name'])) {
echo '<script> alert("Failed to upload file");</script>';
}
}
else {
echo 'Picture uploaded <img scr="featured/uploads/' . $_FILES[$_POST['id']]['name'] . '" width="100">';
}
?>
the problem is it isnt inserting the image name do you know of a way to get that?
move_uploaded_file() should be used.
use basename() on the filename sent by the user if you insist on letting it remain the original name. For safety, you should name the destination file yourself in some manor.
use getimagesize() to determine if the file is an image.