Jump to content

Search the Community

Showing results for tags 'uploading files'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 1 result

  1. Hey, I have written some code below to see if a file exists before uploading the file into the server, and if it does exists then assign the message to the variable $message and the echo it out if $message is not empty. However it doesn't seem to work. I'm not sure what I am doing incorrectly here. The code is under line 19 and 20. $upload_errors = array( UPLOAD_ERR_OK => "No Errors.", UPLOAD_ERR_INI_SIZE => "Large than upload_max_filesize", UPLOAD_ERR_FORM_SIZE => "Larger than from MAX_FILE_SIZE", UPLOAD_ERR_PARTIAL => "Partial Upload", UPLOAD_ERR_NO_FILE => "No File", UPLOAD_ERR_CANT_WRITE => "Can't write to the disk", UPLOAD_ERR_EXTENSION => "File upload stopped by extension"); if(isset($_POST['submit'])) { $tmp_file = $_FILES['file_upload']['tmp_name']; $target_file = basename($_FILES['file_upload']['name']); $upload_dir = "uploads"; $new = file_exists(basename($_FILES['file_upload']['name'])) ? false:true; // Set this to false if the file already exists if($new)// test to see if the file is a new file, and if it is then do the following otherwise diplay message { if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)) { $message = "File uploaded successfully."; } else { $error = $_FILES['file_upload']['error']; $message = $upload_errors[$error]; } } } else { $message = "File could not be written because it already exists"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php if(!empty($message)) { echo "<p>{$message}</p>"; } ?> <form action="uploads.php" enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <input type="file" name="file_upload" /> <input type="submit" name="submit" value="upload" /> </form> </body> </html>
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.