0

Here is my error:

enter image description here

(Added a comment to line 55) One idea would be to modify the script to not have to move the file, but no idea how to do that. Not sure if that would even work because I need it to be outputted to the uploads folder with the same name the file had initially.

<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">   
    Title:<br>
    <input type="text" name="imgTitle" required><br><br>
    Upload a File:  <input type="file" name="imgUploaded" id="imgUploaded"><br><br>
    Comments: <br>
    <textarea  name="imgDesc" rows="4" cols="35"required></textarea><br><br>

    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>
<?php
if (isset($_POST["submit"]) ) { 

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["imgUploaded"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$imgTitle =  $_POST['imgTitle'];
$imgDesc =  $_POST['imgDesc'];
$servername = "sn";
$username = "un";   
$password = "pw";
$dbname = "db";
echo  $imgDesc;
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["imgUploaded"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
if ($_FILES["imgUploaded"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
} else {
    if (move_uploaded_file($_FILES["imgUploaded"]["tmp_name"],$target_file)) // this is line 55 
{
        $imgPath = $_FILES["imgUploaded"]["name"];
        $conn = mysqli_connect($servername, $username, $password, $dbname);
        $sql = "INSERT INTO BrianJones (sqlName, sqlDesc, sqlPath)
        VALUES ('$imgTitle', '$imgDesc', '$imgPath')";
        if (mysqli_query($conn, $sql)) {
            echo "New record created successfully";
        } else {
            echo "Error: " . $sql . "<br>" . mysqli_error($conn);
        }
        mysqli_close($conn);

        echo "The file ". basename( $_FILES["imgUploaded"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
}
?>

Not sure how to fix this, obviously it's an error when trying to move my temp image to the uploads folder because I don't have permission. How can I get around this?

Note: I cannot give myself any permissions, it works fine on localhost but I have to upload it to a web server and test, I can only modify the php and not change any server settings.

1
  • you should check if the folder exists and also if that folder has write permission by server. Note: I cannot give myself any permissions <-- you are wrong. You can change permission of all the folders and files you own. Commented Dec 10, 2015 at 4:47

2 Answers 2

1

From what your Error.

I recommend to fix folder permission to be able to write.

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

1 Comment

Hmm, well now that I think about it, I had to connect to a PW protected SFTP in order to upload the files, so I am assuming I need to enter those details somewhere and make it automatically conect to the SFTP.. how would I go abouts doing that?
0

Try this , it's used to move and upload any file and image and store it to database .

if(isset($_POST['submit'])!=""){
  $name=$_FILES['file']['name'];
  $size=$_FILES['file']['size'];
  $type=$_FILES['file']['type'];
  $temp=$_FILES['file']['tmp_name'];
  $caption1=$_POST['caption'];
  $link=$_POST['link'];
  move_uploaded_file($temp,"upload/".$name);

}

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.