something lot simpler than the usual crap I post about! Trying to create an 'Upload' button to allow user to upload pictures of themselves. The picture should then be renamed pid, and saved to the images folder..
I'm not sure why it isn't working, especially as firebug shows that fileField is being posted.
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['picID'])) {
$pid = $_SESSION["pid"];
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "images/$newname");
header("location: index.php");
exit();
}
?>
Picture upload field
<form method='post' enctype='multipart/form-data' action='playerparent-profile.php?pid=<?=$pid?>'>
<td><label>
<input type="file" name="fileField" id="fileField" />
<input type="hidden" name="picID" id="picID" value="<?=$pid?>">
<input type="submit" name="button" id="button" value="UPLOAD" />
</label></td>
</form>
Just trying to figure out what the heck I'm doing wrong? Any help is appreciated!
That's because this line is wrong I guess. $pid = $_SESSION["pid"]; you should use $pid = $_POST["pid"];
your $newname variable is not getting any name it will always store .png
hope this will help you
I believe this is due to the $newname
variable of your PHP script. Since you are using double quotes, PHP would try to parse any variable that starts with "$" sign and end with space in that string. So in your case, PHP could be trying to look for the variable $pid.jpg
and couldn't find one.
Try concatenation with single quotes instead:
$newname = $pid . '.jpg';
move_uploaded_file($_FILES['fileField']['tmp_name'], 'images/' . $newname);