Jump to content

Recommended Posts

hi i have wrote this code for uploading an image this is my main code

 

 

<?php

$lastimage2 =  mysql_query("SELECT * FROM images WHERE id=$view");

$li2 = mysql_fetch_assoc($lastimage2);

 

if ($page=="P8"&$view>0)

{

echo "<table class=roung bgcolor='#000000'><tr><TD><img src=uploaded/$li2[picname] width='760' height='540'></td></tr></table>";

include 'picclicks.php';

echo "<tr><td>Views: $clicks2 </td></tr>";

 

}

else

{

if ($_SESSION['user'])

{

If ($imagereport='1')

{

}

echo"

<table bgcolor='#000000' class=round><tr><td class=ach>

<form action='index.php?variable=".$page."&fun=upload' method='POST' enctype='multipart/form-dat'>

<input type='file' name='myfile'>

 

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

 

</td></tr></table></form>

";

}

else

{

echo "Please Login to upload new photos!";

}

?>

 

 

then i have this for imageupload.php

 

<?php

if ($_FILES)

{

$username = $_SESSION['user'];

$date =time();

$name = $_FILES["myfile"]["name"];

$type = $_FILES["myfile"]["type"];

$size = $_FILES["myfile"]["size"];

$temp = $_FILES["myfile"]["tmp_name"];

$error = $_FILES["myfile"]["error"];

$hs=$_POST['High Score'];

$g=$_POST['Glitch'];

$f=$_POST['Funny'];

$o=$_POST['Other'];

 

$tags = new Array();

foreach($_POST['tag'] as $tag){

  if($tag){

      tags[] = $tag;

  }

}

$tag = implode(',',$tags);

 

if ($error > 0 )

die("Error uploading file! Code $error.");

else

{

if ($type =="image/jpeg")

{

include 'connect.inc';

move_uploaded_file($temp,"uploaded/".$name);

mysql_query("INSERT INTO images VALUES('','$name','','$username','$date','0','0','0','0','0','0','0','0')");

$uploadreport='1';

 

}

else

{

}

 

}

}

else

{

}

 

?>

 

my database is set right, and this is what i have in my index file

 

 

 

if ($fun=="upload")

{

include 'imageupload.php';

}

 

 

when i click upload it directs it to index.php?variable=P8&fun=upload but nothing shows up on screen

if u need more details plz ask 

 

cheers matt

Link to comment
https://forums.phpfreaks.com/topic/232896-image-upload-problemplz-help/
Share on other sites

A bit confused on what your asking, hope this helps.

 

Mind putting it in [*PHP] tags to make it easier to read?

 

if ($page=="P8"&$view>0)

 

Shouldn't that be this:

 

if ($page=="P8" && $view>0)

 

Also, to display the image, wouldn't you need to call it via header?

 

header("Content-type:image/jpeg");

 

<?php
if ($_FILES)
{
$username = $_SESSION['user'];
$date =time();
$name = $_FILES["myfile"]["name"];
$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];
$temp = $_FILES["myfile"]["tmp_name"];
$error = $_FILES["myfile"]["error"];
$hs=$_POST['High Score']; 
$g=$_POST['Glitch']; 
$f=$_POST['Funny'];
$o=$_POST['Other']; 

$tags = new Array();
foreach($_POST['tag'] as $tag){
   if($tag){
       tags[] = $tag;
   }
}
$tag = implode(',',$tags);

if ($error > 0 )
   die("Error uploading file! Code $error.");
   else
   {
      if ($type =="image/jpeg")
         {
         include 'connect.inc';
         move_uploaded_file($temp,"uploaded/".$name);
         mysql_query("INSERT INTO images VALUES('','$name','','$username','$date','0','0','0','0','0','0','0','0')");
	$uploadreport='1';
	header("Content-type:image/jpeg");

         
         }   
      else
         {
         }

   }
}
else 
{
}

?>

Also:

 

echo "<table class=roung bgcolor='#000000'><tr><TD><img src='uploaded/". $li2[picname] ."' width='760' height='540'></td></tr></table>";

 

Use that instead of

 

echo "<table class=roung bgcolor='#000000'><tr><TD><img src=uploaded/$li2[picname] width='760' height='540'></td></tr></table>";

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.