Resolved
UPLOAD_ERR_CANT_WRITE

Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.

This error will happen in this case image size is shown as zero 0.

1.In php first file is written in temp folder and then it is uploaded required folder , so check your tem folder has enough space.

Dani AI

Generated

Brief, practical checklist and a tiny debug snippet to follow up on the thread (building on notes from , and ). The goal here is not the obvious form-level checks but the less-visible server-side causes that commonly cause a write failure: PHP temp-dir configuration, ownership/permissions, runtime restrictions (open_basedir / chroot / FPM pools), filesystem problems (quota, inode exhaustion, read-only mounts, NFS quirks) and security controls (SELinux/AppArmor/antivirus/mod_security).

Check PHP and the runtime first: confirm which temp directory PHP is actually using, whether file_uploads is enabled, and that post_max_size / upload_max_filesize are appropriate for your test. Also remember that the function that moves the file enforces runtime restrictions on the destination path, so both tmp and destination need to be usable by the PHP process. These behaviors and sanity checks are described in the PHP file-upload and move_uploaded_file documentation. (php.net)

Minimal, safe debug steps to run on the server (log rather than echo) and a short checklist:

  • Log $_FILES and the upload_tmp_dir / sys_get_temp_dir() values and inspect tmp_name and error.
  • Verify the temp directory exists and is writable by the webserver user (owner/group and mode).
  • Check disk free space and inode counts and any per-user quota on that filesystem.
  • Look for SELinux/AppArmor denials or webserver/PHP-FPM error logs if writes are blocked.
    A concise PHP snippet to log this information follows. Use it on a test page (adjust input name and destination):
<?php
error_log(print_r($_FILES, true));
error_log('upload_tmp_dir=' . ini_get('upload_tmp_dir') . ' sys_get_temp_dir=' . sys_get_temp_dir());
$tmp = $_FILES['file']['tmp_name'] ?? null;
error_log('tmp_exists=' . ($tmp && file_exists($tmp) ? 'yes' : 'no'));
if ($tmp && !move_uploaded_file($tmp, '/path/to/dest/' . basename($_FILES['file']['name'] ?? 'u'))) {
    error_log('move_uploaded_file failed: ' . var_export(error_get_last(), true));
}
?>

Quick OS commands (replace /path/to/tmp as needed): df -h /path/to/tmp, df -i /path/to/tmp, ls -ld /path/to/tmp, stat -c '%U:%G %A' /path/to/tmp. If the above checks pass, create a dedicated upload_tmp_dir inside an allowed path, set ownership to the webserver user, restart PHP/FPM or the webserver and retry. For reference on the upload error codes and temp-dir helpers see the PHP manual. (php.net)

Recommended Answers

All 2 Replies

Are you trying to upload file??
Have you put up enctype="multipart/form-data" in form tag??
Or are you using hidden field that contain specific value??
Check these things & hope you will be able solve your query.

Can you please outline your problem a little more detailed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.