I am having issues moving files once uploaded. The upload appears to pass ok with no errors reported. I have 777 on the folder to upload to. The system is wordpress and I have no idea what I am doing wrong.
It should be noted that the form is inside another form. The eventual outcome is to have an image upload (this form, which is inside the larger one) that will allow the user to crop the image and add tags, title description etc before submitting the second form. The final submission of the second form will post to a custom post type and that is working fine. just the moving files and jcrop I am concerned about.
can anyone see a typo in there?
I cannot.
<form method="POST" action="" enctype="multipart/form-data">
<label for="image_upload">Image Upload</label>
<input id="image_upload" type="file" class="text_input" value="" name="file">
<input id="image-upload" type="submit" class="button" value="Upload" name="upload">
<!-- <img id="image-upload" src="<?php echo get_template_directory_uri(); ?>/images/sago.jpg" alt=""> -->
<?php
// Process the upload
if (!empty ($_POST['upload'])) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 100000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "<div> Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br> </div>";
//set temp dir path
$path = $_SERVER['DOCUMENT_ROOT'];
$upload_dir = $path . '/wp-content/uploads/jcrop_temp/';
if (file_exists($path . '/wp-content/uploads/jcrop_temp/' . $_FILES["file"]["name"]))
{
echo "<div style='border: solid 1px #BF5738; color: #BF5738; padding: 1em;'> The File: <span style='color: black;'>" . $_FILES["file"]["name"] . "</span> already exists. Please rename the file before trying again. </div>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);
echo "Stored in: " . $upload_dir . $_FILES["file"]["name"];
echo "<div style='border:solid 1px #E1E1E1; max-width: 710px; text-align: center;'>
<img id='image-upload' src='" . "/wp-content/uploads/jcrop_temp/" . $_FILES["file"]["name"] . "'>
</div>
";
}
}
}
else
{
echo "Invalid file";
}
//end upolad if
}
?>
</form>