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
https://forums.phpfreaks.com/topic/249471-error-while-file-upload/
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>

@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

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

@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

Archived

This topic is now archived and is closed to further replies.

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