Jump to content

Error while file upload


believeinsharing

Recommended Posts

Hi want to upload file using form's input type="file" then i want to display it on another page,

As i am new to PHP i am  doing this step by step so that I can test each step and go ahead.

 

My first step is to upload file and check if its uploading in temp location.. I got same code from net..

I am using notepad++ thats why not sure abt syntax error,

 

What I did is:

 

<html>

<body>

 

<form action="index.php" method="POST" enctype="multipart/form-data">

Image:

<input type="file" name="image">

<input type="submit" value="Upload">

 

</form>

 

<?php

mysql_connection("localhost","root","admin") or die(mysql_error());

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

 

echo $file = $_FILES['image']['tmp_name'];

 

 

?>

</body>

</html>

Link to comment
Share on other sites

ok, couple of things,  why do you need a database connection for this? and is this posting back to index.php, or is index.php another file?.  try this:

<html>
<body>

<form action="index.php" method="POST" enctype="multipart/form-data">
Image: 
<input type="file" name="myImage">
<input type="submit" value="Upload">

</form>

<?php 
if($_FILES){

  echo "Name: " . $_FILES["myImage"]["name"] . "<br />";
  echo "Size: " .  ( $_FILES["myImage"]["size"] /1024) . "Kb<br />";
  echo "Type: " . $_FILES["myImage"]["type"]  . " <br />";
  echo "temp Directory: " . $_FILES["myImage"]["tmp_name"];
}
?>
</body>
</html>

Link to comment
Share on other sites

@gristoi:

Hey thanks its working fine with ur code...

 

I am using database because I wanted to add this image to database in next state and index.php is a same file and I am using it as POST back..

 

Can u plz tell, wht was the prob in my code..  As I am new to PHP I appreciate ur help which will help to understand basic...

 

Thanks alot

Link to comment
Share on other sites

your problem was with:

mysql_connection("localhost","root","admin") or die(mysql_error());

should have been 

mysql_connect("localhost","root","admin") or die(mysql_error());

if you werent getting any warnings or errors showing then you will need to turn on your error checking. to do this you can put this at the very top of your page:

<?php
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);

 

this will help you a lot, by showing you all of the errors and warnings that your code makes.

 

good luck

Link to comment
Share on other sites

@gristoi:

 

Got it... thx will remember that and will help me in future...

 

My last question..

 

lets say my code is:

<body>

<form action="index2.php" method="POST" enctype="multipart/form-data">

Image:

<input type="file" name="myImage" />

<input type="submit" value="Upload" />

</form>

<?php

 

echo $_FILES["myImage"]["tmp_name"];

 

?>

</body>

 

interesting thing is... this code is working fine in IE but not working in chrome...

and yesterday whole day I was trying it on chrome..

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.