Jump to content

uploading images


sandbudd

Recommended Posts

this script uploads the image to the file and displays the jpeg images but when trying to upload a png file it puts it in the database but in the image file it uploads the image.png but is all black?  Thanks for the help in advance as I am sure this is an easy fix.

 

<?php

//This is the directory where images will be saved
// This is the temporary file created by PHP 
$uploadedfile = $_FILES['photo']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// Resize the image
$newwidth=185;
$newheight=($height/$width)*$newwidth;

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 
$target2 = "../images/coupon/";
$target2 = $target2 . basename( $_FILES['coupon']['name']);
$target3 = "../images/map/";
$target3 = $target3 . basename( $_FILES['map']['name']);
$target4 = "../images/menu/";
$target4 = $target4 . basename( $_FILES['menu']['name']);

//This gets all the other information from the form
$company=$_POST['company'];
$bold=$_POST['bold'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$phone=$_POST['phone'];
$asian=$_POST['asian'];
$american=$_POST['american'];
$coffee=$_POST['coffee'];
$fun=$_POST['fun'];
$italian=$_POST['italian'];
$mexican=$_POST['mexican'];
$seafood=$_POST['seafood'];
$upscale=$_POST['upscale'];
$recommend=$_POST['recommend'];
$email=$_POST['email'];
$website=$_POST['website'];
$pizza=$_POST['pizza'];
$fastfood=$_POST['fastfood'];
$map=($_FILES['map']['name']);
$photo=($_FILES['photo']['name']);
$coupon=($_FILES['coupon']['name']);
$menu=($_FILES['menu']['name']);
$greek=$_POST['greek'];
$chinese=$_POST['chinese'];
$japanese=$_POST['japanese'];
$korean=$_POST['korean'];
$thai=$_POST['thai'];
$vietnamese=$_POST['vietnamese'];

// Connects Database
mysql_connect("", "", "") or die(mysql_error()) ;
mysql_select_db("") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO `fishers` VALUES ('$id','$company','$bold','$address','$city','$state', '$phone','$asian','$american','$coffee','$fun','$italian','$mexican','$seafood','$upscale','$recommend','$email','$website','$photo','$coupon','$map','$pizza','$fastfood','$menu','$greek','$chinese','$japanese','$korean','$thai','$vietnamese')") or die(mysql_error());
{

//Tells you if its all ok
echo "The file has been uploaded, and your information has been added to the directory";
}
//Writes the photo to the server
$filename = "../images/". $_FILES['photo']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
// has completed.
if(move_uploaded_file($_FILES['coupon']['tmp_name'], $target2))
if(move_uploaded_file($_FILES['map']['tmp_name'], $target3))
if(move_uploaded_file($_FILES['menu']['tmp_name'], $target4))
{
echo "The file has been uploaded, and your information has been added to the directory";
}

?>

Link to comment
Share on other sites

Hi

i have created this one long back for some fellow..

it displays the images that has been uploaded..

 

just have a look..

 

<?php
if ($_REQUEST[completed] == 1) {
$newname = uniqid("").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"img_upload/$newname ");
} ?>

<html>
<head><title>Upload page</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-color: #7BC623;
}
-->
</style></head>
<body>
<p>
<?php if ($_REQUEST[completed] != 1) ?>
</p>
<p> <b>Please upload an image</b> <br>
</p>
<form enctype=multipart/form-data method=post action="upload_new.php">
<input type=hidden name=MAX_FILE_SIZE value=1500000>
<input type=hidden name=completed value=1>
Choose an image:
<input type=file name=mailfile> and
<input type="submit" name="Submit" value="Submit"></form>
<p>
<?php 
//echo "$newname ";

$pic = "'/img_upload/'.$newname";
echo $pic."<br>";
print ("<IMG SRC =img_upload/$newname>");

// load the file to send:
//readfile($pic);
?>
<!--<img src="<?php $pic ?>" alt="File" border=0>-->
</p>
<hr>

</body></html>

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.