hello i am looking script image and html or text file upload with option make file name and file deletion
any body can help?

Dani AI

Generated

Likely causes: the HTML form not sending the file, PHP refusing the upload, or the target folder not existing / not writable. was right to suspect the missing uploads directory, and ’s example points in the right direction but misses a few real-world checks you’ll need to debug and secure the flow.

Checklist to confirm

  • The form must use multipart/form-data and the file input must have a name the handler expects.
  • Verify PHP can accept uploads: file_uploads is On, upload_max_filesize and post_max_size are large enough, and upload_tmp_dir exists.
  • Make sure the uploads folder exists and is owned/writable by the webserver user (example shell commands: create the folder, chown to the webserver user, set permissions).
  • Inspect $_FILES and the upload error code to see why the transfer failed — dump it to the page or the error log while debugging.

Quick helper (PHP) — map the upload error code to a message:

function uploadErrorMessage($code) {
    $map = [
        UPLOAD_ERR_OK => 'No error',
        UPLOAD_ERR_INI_SIZE => 'Exceeds server limit',
        UPLOAD_ERR_FORM_SIZE => 'Exceeds form limit',
        UPLOAD_ERR_PARTIAL => 'Partial upload',
        UPLOAD_ERR_NO_FILE => 'No file sent',
        UPLOAD_ERR_NO_TMP_DIR => 'Missing temp dir',
        UPLOAD_ERR_CANT_WRITE => 'Failed to write to disk',
        UPLOAD_ERR_EXTENSION => 'Blocked by extension',
    ];
    return $map[$code] ?? 'Unknown upload error';
}

Safe delete pattern (validate path before unlinking):

$base = __DIR__ . '/uploads/';
$target = realpath($base . $userFilename);
if ($target && strncmp($target, $base, strlen($base)) === 0 && is_file($target)) {
    unlink($target);
}

Security and troubleshooting notes

  • Never trust the original filename: sanitize or generate a server-side name (use a random/unique token).
  • Validate uploads by type (use getimagesize() for images) and enforce an allowlist of extensions.
  • For debugging, temporarily log phpinfo() and $_FILES, and check the webserver/PHP error logs.

Address those items first and you’ll find the missing files or the specific upload error quickly.

Recommended Answers

All 7 Replies

So google:

  • PHP upload (you will learn how to rename there)
  • PHP delete file

Not that difficult, but at least show some effort and try!

You can find what you need in the documentation.

Here is a small example. I haven't tested out but will give you some good direction.

//Form processing
if(isset($_POST['submit'])){

        $upload_folder = 'uploads/';

        if(isset($_POST['new_file_name'])){
            $file_path = $upload_folder . $_POST['new_file_name'];
        }else{
            $file_path = $upload_folder . basename($_FILES['file']['name']);
        }

        if( move_uploaded_file($_FILES['file']['tmp_name'], $file_path)){
            echo 'File has been uploaded';
        }else{
            echo 'Error, file has not been uploaded';
        }

    }



    //Submit Form

    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
        <input type="text" name="new_file_name" value="" placeholder="Give new filename (Optional)" />
        <input type="file" name="file" value="" />
        <input type="submit" name="submit" value="Submit File"  />
    </form>

no file in uploads folder

not showing any file uploads folder,
somthing wrong

not showing any file uploads folder,
somthing wrong

So show us some code so we can help you.

Again: Show some effort and try.

maybe because you need an uploads/ directory on your site for the images to upload to?

http://www.amayam.com/uploads/ is a 404.

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.