Alright, so I am having an issue with my image uploading script/application. I have tried debugging time after time again and still cannot find out what the issue is. The code seems to be fine, but for some reason or another the file looks like it's not get saved in the temp directory so that it can then moved over to my uploads directory on my server. I have made certain that the directory(uploads) that i'm trying to upload it to, including the temp directory, have read/write/execute permissions set and that uploads is set to on in the php.ini folder. I have a feeling that the files are never getting saved to the temp folder, but i'm not sure how to check if that is the case, since i understand the file is deleted after the script finishes executing. I hope you guys can help me out, because I have no clue what to do. There's the code for my script.
Also, this is where my issue is located at.
if (is_uploaded_file($filetempname)) {
$final = "../public_html/uploads/" . $filename;
$result = move_uploaded_file($filetempname, $final);
if($result)
{
echo 'success';
echo "<br>Stored in: " . "public_html/uploads/" . $filename;
}
else
{
echo 'Image was not uploaded.';
}
$result= move_uploaded_file($filetempname, $final) keeps returning false with no sign of an error occuring. I know that if the file type is not correct it'll return false and won't do copy anything and also it'll return false if the file cannot be moved for some reason and it will raise an alert message saying that. However, I'm not having a message raised at all. All I know is that it returns false and it doesn't do what it should do.
<?php
error_reporting(E_ALL);
print_r($_FILES);
$filetype = $_FILES["file"]["type"];
$filename = $_FILES["file"]["name"];
$filetempname = $_FILES["file"]["tmp_name"];
$filesize = $_FILES["file"]["size"];
$error = $_FILES["file"]["error"];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $filename));
if ((($filetype == "image/gif")
|| ($filetype == "image/jpeg")
|| ($filetype == "image/jpg")
|| ($filetype == "image/pjepg")
|| ($filetype == "image/x-png")
|| ($filetype == "image/png"))
&& ($filesize < 1000000)
&& in_array($extension, $allowedExts)) {
if ( $error > 0) {
echo "Error: " . $error . "<br>";
}
else {
echo "Upload: " . $filename . "<br>";
echo "Type: " . $filetype . "<br>";
echo "Size: " . ($filesize / 1024) . " KB<br>";
echo "Stored in: " . $filetempname . "<br>";
if (file_exists("../public_html/uploads/" . $filename)) {
echo $filename . " already exists. ";
}
else {
if (is_uploaded_file($filetempname)) {
$final = "../public_html/uploads/" . $filename;
$result = move_uploaded_file($filetempname, $final);
if($result)
{
echo 'success';
echo "<br>Stored in: " . "public_html/uploads/" . $filename;
}
else
{
echo 'Image was not uploaded.';
}
}
}
}
}
else {
echo "Invalid file";
}
?>
Here's the code for the form.
<form enctype="multipart/form-data" method="post" action="scripts/snap.php">
<!--<p>
<input id="plat" class="plat" name="plat" type="hidden" value="" />
<input id="plon" class="plon" name="plon" type="hidden" value="" />
</p>-->
<div class="row">
<label for="file">Select an image to Upload</label><br />
<input type="file" name="file" id="file" /><!--onchange="fileSelected();"-->
</div>
<div id="filename"></div>
<div id="fileSize"></div>
<div id="fileType"></div>
<div class="row">
<input type="submit" name="submit" value="Submit" />
<!--<input type="button" onclick="uploadFile()" value="Upload" />-->
</div>
<div id="progressNumber"></div>
</form>
$filetype == "image/pjepg"should be$filetype == "image/pjpeg"- Pitchinnateuploaddirectory? - Pitchinnate