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!
<?
if ($_FILES[icon][name] != "") {
@copy($_FILES[icon][tmp_name],"/home/content/nottelling/html/icons/".$_FILES[icon][name]) or $icon_result = "Didn't Change Eyecon";
$sql_for_icon = "UPDATE $table_name SET picture = '$image_name' WHERE username = '$_SESSION[username]'";
$result_for_icon = @mysql_query($sql_for_icon,$connection) or die(mysql_error());
$icon_result = "icon Changed.<img src=\"http://www.mywebsite.com/icons/$_SESSION[username]\">";
} else if ($_FILES[icon][name] == "") {
$icon_result = "Didn't Change icon";
}
echo "$icon_result";
?>
It all works when there's no <img> tag in the code. What happends is without the img tag it uploads the image to the sever but with it it doesn't for some reason it just stays the same image everytime I try and upload it.
unless you have a rewrite script in the icons directory, it will never match the session username to the icon.
some browsers send the full path of the file in the name field of the files array, use basename() on it to ensure you get just the filename if you insist on using user submitted data.
Thanks for the reply fayd. But can you please explain the problem of my problem? What is it the problem with my script and what's the reason to change my copy to move_uploaded_file()??? Expain why?
unless you have a rewrite script in the icons directory, it will never match the session username to the icon.
But I'll explain further. Your copy() call places the file into the icons directory using the original filename. You are trying to access it in your image tag using the username stored in sessions, which is not likely to match.
copy() is not a smart function. move_uploaded_file() checks to ensure the file you are trying to move/copy is an actual uploaded file.
Asking someone to answer your question is redundant and annoying, it decreases the chances someone is going to want to answer your question...
Anyways filesize() will give you the site in bytes of the filename that you pass to it, getimagesize() is good for getting the dimensions of the image in pixels. You can also set a max upload size in php.ini and in your form, even with the form and php.ini limitations in place its always good to verify that the is actually the right size using filesize.
You're going to need to elaborate a bit if you want help.. how does what work? Did you actually read the documentation? Is there a specific problem you're having with it?