PHP Script File Upload

Check your images folder; I uploaded a smiley png.

Nope, the image was not saved, nor was the image filename written to my database.

Okay, i tested this with my website and it worked for me, try this

$targetDir = __DIR__ . "/../images/";
1 Like

That didnt work.

!empty($_FILES[“imageupload”][“tmp_name”]) is resolveing to true, so the code to rename the file never runs.

Provide me the full code, without it i can’t know for sure what’s the issue.

I’ve done some debugging, and this is the error on the file uploaded.
UPLOAD_ERR_NO_TMP_DIR, value 6, means that no temporary directory is specified in the
php.ini.

Below code works for me,

($_FILES["files"]["tmp_name"])

And I can’t be of any help unless you provide your full uploading code.

this could be related to the tmp folder issues all wordpress hostings on IF are currently having.

[Code Removed]

Can you share the thread on this please? Must be the same thing.
Something seems to be wrong with the php.ini config

Hey, it’s not an error from your end; it’s a server issue. I checked with my website, and my images are not uploading either.

1 Like

You found it out by youself, there’s several more and messing with .htaccess doesn’t help.
Tried to set manually a tmp folder for myself and didnt help.

php_value upload_tmp_dir /home/vol00_0/infinityfree.com/if0_00000000/softhub.xyz/htdocs/tmp

and that didn’t help, guess we’ll have to wait for the admin to tweak that php.ini

1 Like

@ifastnet hello
Please Check php.ini file or hosting system because I also have this problem even though my script is correct and it was working.

Hey there, Please keep in mind that users can’t edit or view the php.ini file due to security reasons. As I mentioned before, we are all going to have to wait until the admin fixes this issue.

Try this code:

if(empty($_FILES["imageupload"])) {
    exit("File is empty.");
}
$targetDir = $_SERVER["DOCUMENT_ROOT"]."/images/".basename($_FILES["imageupload"]["name"]);
if(move_uploaded_file($_FILES["imageupload"]["tmp_name"], $targetDir)) {
    echo "Successfully uploaded ".$_FILES["imageupload"]["name"].".";
} else {
    echo $_FILES["imageupload"]["error"]);
}

Like I said before, it’s not an issue with the code; something is wrong with the php.ini.

And your code would be more clear and would prevent any errors if you used it like this.

$targetDir = $_SERVER["DOCUMENT_ROOT"] . "/images/";
$targetFile = $targetDir . basename($_FILES["imageupload"]["name"]);
1 Like

I don’t think anything is wrong with the php.ini file because it works just fine for me.

1 Like

No, there is something wrong with the PHP. My apologies for not addressing it correctly.

1 Like
5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.