Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7926507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:48:14+00:00 2026-06-03T18:48:14+00:00

I just implemented an image upload to MySQL via PHP. But i want to

  • 0

I just implemented an image upload to MySQL via PHP. But i want to upload text, pdf, doc, zip file to MySQL. This is my code. How to change it ?

// uploadAction.php

mysql_connect("localhost", "root", "1989") 

or die(mysql_error());

mysql_select_db("uploadfile") or die(mysql_error());


$sql_id = "SELECT (MAX(id)+1) as \"result\" FROM save";

$rs_id = mysql_query($sql_id);

$row_id = mysql_fetch_assoc($rs_id);

$id = $row_id['result'];

if($id == null)

$id = 1;    

$newName = '';  

$file = $_FILES['photo']['name'];

if ((($_FILES["photo"]["type"] == "image/gif")||

($_FILES["photo"]["type"] == "image/jpeg")||

($_FILES["photo"]["type"] == "image/pjpeg"))

&& ($_FILES["photo"]["size"] < 200000))
{

if ($_FILES["photo"]["error"] > 0)

    echo "Return Code: " . $_FILES["photo"]["error"] . "<br />";

  else{  

      $newName = "$id.".basename($_FILES["photo"]["type"]);

      move_uploaded_file($_FILES["photo"]["tmp_name"], "images/" . $newName);

      }

} 

else

  {

  echo "Invalid file";

  }

$queryUser = "INSERT INTO save VALUES(NULL, \"$newName\")";

$insert = mysql_query($queryUser);

if(!$insert){

    echo mysql_error().'Upload Fail';

  }else {

    echo "<script>alert('Upload Sccessful');";

    echo 'window.location="index.php";</script>';
}

Database SQL

CREATE TABLE `save` (

  `id` int(255) NOT NULL auto_increment,

  `photo` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,

  PRIMARY KEY  (`id`)

)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:48:15+00:00Added an answer on June 3, 2026 at 6:48 pm

    Try this:

    if ($_FILES["photo"]["type"] == "image/gif" ||
    $_FILES["photo"]["type"] == "image/jpeg" ||   
    $_FILES["photo"]["type"] == "image/pjpeg" || 
    $_FILES["photo"]["type"] == "application/zip" || 
    $_FILES["photo"]["type"] == "application/pdf" || 
    $_FILES["photo"]["type"] == "application/msword" || 
    $_FILES["photo"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
    

    You can look at the different MIME-types here: http://en.wikipedia.org/wiki/Internet_media_type

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have implemented placeholder just like twitter and google does but i want to
Context: I've just written a PHP file upload handler that saves any incoming file
I just implemented QuickSort algorithm from book and got weird output. It works but
I have currently implemented this image slider http://www.dreamcss.com/2009/04/create-beautiful-jquery-sliders.html on a site but for some
So I have an HTML form where a user can upload an image. This
I have a register page that has a file upload button on it. This
I have just implemented these ToggleButtons using ControlTemplates that set the Image content according
I have an image upload script, originally I kept it in a file called
I am implementing an image upload system in PHP, The following are required: Have
I've just implemented collision detection using SAT and this article as reference to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.