0

I'm trying to create a script that would allow the user to upload images onto the server. I've implemented the script,though once I tried to upload an image, the script follows through but no image appears on the server. Any ideas?

PHP:

<?php
require_once("connect.php");
ini_set('display_errors', 'on'); 
error_reporting(E_ALL);

echo __LINE__;

$allowedExtensions = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["image"]["name"]));
print_r($_FILES['image']);
echo $extension;

if((($_FILES["image"]["type"] == "image/gif") || ($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"]=="image/pjpeg") || ($_FILES["image"]["type"] == "type/png")) && ($_FILES["image"]["size"] <= 102400) && in_array($extension, $allowedExtensions)) {

        echo __LINE__;
        if($_FILES["image"]["error"] > 0) {
                $fileUploadFail = true; 
        }
        else {
               chmod("uploadImages/", 0755);
               move_uploaded_file($_FILES["image"]["tmp_name"], "uploadImages/" . $_FILES["image"]["name"]);
        }

} else {
        $fileUploadFail = true;
        echo __LINE__;
}   
        $fileName = $_FILES["image"]["name"];
        chmod("uploadImages/", 0600);
        echo __LINE__;
        /*if($fileUploadFile) {
              header("Location: uploadArt.php");
        }
        else {
             $title = $_POST['title'];
             $description = $_POST['description'];
             mysql_query("INSERT INTO `Art`(`File Name`, `Description`, `uploadLocation`, `Index`) VALUES('$title', '$description', 'uploadImages/$fileName', '')");
              header("Location: viewArt.php");
        }*/
  ?>

Output I receive:

6Array ( [name] => comps_tech.png [type] => image/png [tmp_name] => /tmp/phpgQKnMJ [error] => 0 [size] => 661 ) png2529

HTML:

<form id = "uploadDesigns"  enctype="multipart/form-data" name="Upload" method="post" action="fileUpload.php" >
<label for="title">Enter name of design:</label><input type = "text" id = "title" name = "title" size="50"><br /><br />
<label for="image">Upload image:<br />(max 100KB)</label> <input type = "file" id = "image" size = "51" name = "image"><br /><br />
<label for="description">Description:</label> <textarea id = "description" name = "description" rows = "4" cols = "20"></textarea><br /><br />
<button type="submit">Submit Art</button>
</form>

Thanks!

3 Answers 3

3

You have

input type = "file" id = "image" size = "51" name = "image"

But are referencing

$_FILES["file"]["type"] 

The "file" in the $_FILES refers to the name of the file input. This is "image", not "file"


The complete the answer (after fixing other issues and debugging); the last error is that

$_FILES["image"]["type"] == "image/png"

needs to be added to the if statement.

Sign up to request clarification or add additional context in comments.

14 Comments

i changed it, still seems to be a problem?
Next thing to check is permissions. You set uploadedimages to 600 (rw) but you need 700 (rwx) for a directory. For now, set permissions to 777 to get it to work, and then 775 (if that files, check which group you're running as) then 755 (if that fails, check the user you're running as).
Oh - you also set permissions on "/uploadedImages/" (absolute reference, from root, THAT WILL PROBABLY NOT EXIST), but you upload to "uploadedImages/" which is a relative reference, i.e. from where you are. So chance permissions on the relative directory, not the absolute one.
hmmm.. i tried all the permissions, seems none of them work. May just be Kodingen doesn't allow me to upload files through PHP?
What errors do you get? add "ini_set('display_errors', 'on'); error_reporting(E_ALL);" near the top of your PHP file. Then add "echo LINE;" in various places to check the script runs through the flow you expect. Type "print_r($_FILES);" as well to check the file is upladed. You need some basic debugging - we can't be phsycic ;)
|
0

You need to give write permissions for uploadImages.

2 Comments

i'm not too sure, how do I check that?
how are you testing your code? You must have a testing environment set such as xammp, wamp etc
0

Ur file directory structure should b like this.

1) test.php 2) uploadImages/ (this folder needs to be created by u ).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.