Jump to content

[SOLVED] Image Uploading followed by filling a text box with url of that image


Malevolence

Recommended Posts

Hi AGAIN!

 

1 Last question regarding my Items Database. I want to be able to get people to upload an image (I know this script) and I want to limit it to a certain size (35x35px) and filetypes (gif, tiff, png, mng, jpg, jpeg, bmp, wbmp) and uploaded to ./idb/pictures/

 

This uploader will be within a Form so I don't want it to redirect the user anywhere. What I DO want is to make sure that if the user uploads a file and it is successful, then it will fill the text box above it (input name="imgurl") with the URL to the image that they just uploaded. I also want to make it so that the user cannot edit the text box at any time- the only way they can fill the text box, is if the PHP script returns an URL of the image that they upload.

 

Is this possible??

 

Thanks in Advance,

Dan.

Link to comment
Share on other sites

<?
if(isset($Submit)){
	//If the Submitbutton was pressed do:
	$img = $_FILES['imagefile']['tmp_name'];     
	list($width, $height, $type, $attr) = getimagesize($img);
	echo "<br><br><font color=\"#FFFF00\">Your image dimensions<br>";
	echo "width = $width<br>";
	echo "height = $height</font><br><br>";
	if ($_FILES['imagefile']['type'] == "image/jpg" || "image/jpeg" || "image/gif" ||  "image/tiff" ||  "image/png" ||  "image/mng" ||  "image/bmp" ||  "image/wbmp"){
		if($width>35 || $height>35){
			die("<font color=\"#FF0000\"><b>Image exceededs image dimension limits.</b></font>");
		} else {
			copy ($_FILES['imagefile']['tmp_name'], "./idb/pictures/".$_FILES['imagefile']['name']) or die ("Could not copy"); 
			$path = "<your domain>/imb/pictures/$_FILES['imagefile']['name']";
                                echo "<br>"; 
			echo "?><input type="text" name=\"imgurl\" readonly value=\"$path/>";
                                echo "Name: ".$_FILES['imagefile']['name']."<br>"; 
			echo "Size: ".$_FILES['imagefile']['size']."<br>"; 
			echo "Type: ".$_FILES['imagefile']['type']."<br>"; 
			echo "Copy Done...."; 				
		}
	} else {
		echo "<br><br>";
		echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
	}
} else {
	echo "
	    <h3><font color=\"#FF0000\">Image must be 35px by 35px (height, width)</font></h3>  
		<form action\"\" method=\"post\" name=\"image_upload\" enctype=\"multipart/form-data\">
		<input type=\"file\" name=\"imagefile\">
		<br>
		<input type=\"submit\" name=\"Submit\" value=\"Submit\"> 
		</form>";
}
?>

;) beaten

Link to comment
Share on other sites

OK I really don't understand anything you just gave me drummer101.

 

Why are there so many backslashes?

 

Could you integrate it into the following? I didn't want it to be a seperate form:

 

<?php
$db_host = "****";
$db_user = "****";
$db_pwd = "****";
$db_name = "****";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<html>
<head>
<title>RuneScapez.com :: Items DB Submission Form</title>
</head>
<body>
<p><font size="4" face="Arial, Helvetica, sans-serif"><strong>Items Database Submission 
  Form</strong></font><font size="2" face="Arial, Helvetica, sans-serif"> (Version 
  0.3_alpha)</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif"> 

  <?php
if (!isset($_POST['submit'])) {
?>

  <font color="#666666">* - Required</font></font> </p>
<p><font size="2" face="Arial, Helvetica, sans-serif">Please make sure you Delete 
  all Example Text if you are to leave a Field Blank. Try to fill out as many 
  Fields as you can. Please note that the items Database Submission form and the 
  Items Database itself is still under construction; however, please help us by 
  filling in the form as the data will be kept no matter how much we change/ruin 
  the database!</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif">Note From RuneHQ: We can 
  take legal action against anyone found stealing our content. ubmitted information 
  is Copyrighted to RuneHQ. It's use on other sites is expressly forbidden. Do 
  Not ask if you can use our guides or images, the answer is and always will be 
  NO!</font></p>
<p><em><font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif">This means that you 
  must NOT take information about items from RuneHQ's Database. Please find information 
  yourself; we respect the rights of other Fansites, so please only copy data 
  that stays the same (Such as Examine Info - That isn't copying as it is the 
  same on the Game itself). Please type out things like Notes yourself; do NOT 
  copy notes from RuneHQ. Thank You!</font></em></p>
<p><font size="2" face="Arial, Helvetica, sans-serif"><em>Any Spam Submissions 
  will be deleted without warning. Thank You for Participating!</em></font></p>
  
<form action="" method="post">

  <p><font size="2" face="Arial, Helvetica, sans-serif">Item Name*: 
    <input name="itemname" type="text" size="20" maxlength="20">
    - Such as 'Book of Balance' or 'Banana'<br>
    <br>

    Item Type: 
    <select name="itemtype" id="itemtype">
<option value=""></option>
<option value="Ammo/Projectiles">Ammo/Projectiles</option>
<option value="Armour">Armour</option>
<option value="Books/Scrolls">Books/Scrolls</option>
<option value="Clothing/Appearance">Clothing/Appearance</option>
<option value="Currency/Tokens">Currency/Tokens</option>
<option value="Food/Drink">Food & Drink</option>
<option value="Handy/Tools">Handy/Tools</option>
<option value="Jewellery/Enchanted">Jewellery/Enchanted</option>
<option value="Keys and Thieving">Keys and Thieving</option>
<option value="Magic-Related Items">Magic-Related Items</option>
<option value="Miscellaneous">Miscellaneous</option>
<option value="N/A">N/A</option>
<option value="Potions/Poisons">Potions/Poisons</option>
<option value="Quest Items">Quest Items</option>
<option value="Rare/Discontinued">Rare/Discontinued</option>
<option value="Raw Materials">Raw Materials</option>
<option value="Rewards">Rewards</option>
<option value="Unusable">Unusable</option>
<option value="Weapon">Weapon</option>
    </select>
    - Select an option from the List<br>
    <br>

    Street Price: 
    <input name="streetprice" type="text" size="17" maxlength="17">
    - Number followed by either: 'gp', 'k gp' or 'mil gp'<br>
    <br>

    High Alch Reward/Special Store Sell Price: 
    <input name="highalch" type="text" size="17">
    <br>
    <br>

    Low Alch Reward/General Store Buy Price: 
    <input name="lowalch" type="text" size="17">
    <br>
    <br>

    Members Only?: 
    <select name="memberitem" id="memberitem">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Stackable?: 
    <select name="stackable" id="stackable">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Quest Item?: 
    <select name="quest" id="quest">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Tradable?: 
    <select name="tradable" id="tradable">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Item Stat Gain/Loss:<br>
    <textarea name="stats" cols="33" rows="5" wrap="VIRTUAL">Example:
Prayer: +1
Melee: +25
Range: -12</textarea>
    <br>
    <br>

    Requirements to Use/Wear: <br>
    <textarea name="reqtowear" wrap="VIRTUAL">Example:
Need to have completed 'Monkey Madness'</textarea>
    <br>
    <br>

    Used for: <br>
    <textarea name="usedfor" wrap="VIRTUAL">Example:
Melee Fighting.
Slashing Spiders Webs in Wilderness</textarea>
    <br>
    <br>

    Effects the Item has: <br>
    <textarea name="effects" wrap="VIRTUAL">Example:
Poison taking off 2HP every 30 seconds.</textarea>
    <br>
    <br>

    Right Click Options:<br>
    <textarea name="itemoptions" wrap="VIRTUAL">Example:
Eat, Use, Examine, Drop</textarea>
    <br>
    <br>

    Respawn Areas: <br>
    <textarea name="respawnareas" cols="20" rows="3" wrap="VIRTUAL">Example:
Lumbridge Swamp, Near Goblins</textarea>
    <br>
    <br>

    How and Where is the Item Retrieved?:<br>
    <textarea name="wherefound" wrap="VIRTUAL">Example:
Killing the Kalphite Queen or Player Trading</textarea>
    <br>
    <br>

    Notes/Tips: <br>
    <textarea name="notes" cols="45" rows="6" wrap="VIRTUAL"></textarea>
    <br>
    <br>

    Examine Info: 
    <input name="examine" type="text" size="56">
    <br>
    <br>

    Your Username/Nickname: 
    <input name="username" type="text" size="20">
    <br>
    <br>

Item Image: (Please Upload one from your Computer by Clicking 'Browse')

<!-- This is where I want the upload, browse and the remaining text box with the URL to appear. Thanks for your help! -->




<!-- The below is the Submit and Reset Button for the WHOLE form including the URL for the image uploaded. -->

    <input type="submit" name="submit" value="Submit New Item">
    <input name="reset" type="reset" id="reset" value="Clear Form">
    </font></p>
</form>
<font size="2" face="Arial, Helvetica, sans-serif"> 

<!-- The php code below sends all of the values of the textboxs/select boxes to my MySQL Database, I've added 'imgurl' in there now. -->
<?php
} else {
$itemname = $_POST['itemname'];
$itemtype = $_POST['itemtype'];
$streetprice = $_POST['streetprice'];
$highalch = $_POST['highalch'];
$lowalch = $_POST['lowalch'];
$memberitem = $_POST['memberitem'];
$stackable = $_POST['stackable'];
$quest = $_POST['quest'];
$tradable = $_POST['tradable'];
$stats = $_POST['stats'];
$reqtowear = $_POST['reqtowear'];
$effects = $_POST['effects'];
$itemoptions = $_POST['itemoptions'];
$respawnareas = $_POST['respawnareas'];
$wherefound = $_POST['wherefound'];
$notes = $_POST['notes'];
$examine = $_POST['examine'];
$username = $_POST['username'];
$imgurl = $_POST['imgurl'];
mysql_query("INSERT INTO `items` (itemname, itemtype, streetprice, highalch, lowalch, memberitem, stackable, quest, tradable, stats, reqtowear, effects, itemoptions, respawnareas, wherefound, notes, examine, username) VALUES ('$itemname', '$itemtype', '$streetprice', '$highalch', '$lowalch', '$memberitem', '$stackable', '$quest', '$tradable', '$stats', '$reqtowear', '$effects', '$itemoptions', '$respawnareas', '$wherefound', '$notes', '$examine', '$username', '$imgurl')");
echo "Your Item has been Successfully Submitted into the Database! Thank You.";
}
?>

</font> 

</body>

</html>

 

 

Thanks; it's a huge task and I am really a newbie at PHP.

 

Malev.

Link to comment
Share on other sites

His echo's were echo " stuff to echo " (with double quotes) so when he put the double quotes in the tags such as name="name", if you did that the second name wouldn't be in a quote, so either do as drummer did and add \ to each "" other than those for the echo. Or as an alternative you should change the echo quotes to single quotes echo ' <input name="name"> '; - that way it'll work just as well.

 

Sam

Link to comment
Share on other sites

I mean how do I put drummer101's code so that it works within the form? He's made a script that uploads an image and that's it.

 

I want a form with all the objects that are ALREADY there AND the upload image script...

 

Also, drummer101's code is full of syntax errors. :S

 

I'm really confused :S:S

Link to comment
Share on other sites

corrected not tested trie mate...............

 

post results......

 

<?php
if(isset($_POST['Submit'])){
$img = $_FILES['imagefile']['tmp_name'];     
list($width, $height, $type, $attr) = getimagesize($img);
echo "<br><br><font color='#FFFF00'>Your image dimensions<br>";
echo "width = $width <br>";
echo "height = $height</font><br><br>";
if ($_FILES['imagefile']['type'] == "image/jpg" || "image/jpeg" || "image/gif" ||  "image/tiff" || "image/png" ||  "image/mng" ||  "image/bmp" ||  "image/wbmp"){
if($width>35 || $height>35){
die("<font color=\"#FF0000\"><b>Image exceededs image dimension limits.</b></font>");
} else {
copy ($_FILES['imagefile']['tmp_name'], "./idb/pictures/".$_FILES['imagefile']['name']) or die ("Could not copy"); 
$path = "<your domain>/imb/pictures/".$_FILES['imagefile']['name']."";
echo "<br>"; 
echo "?>
<input type='text' name='imgurl' readonly value='$path' />";
echo "Name: ".$_FILES['imagefile']['name']."<br>"; 
echo "Size: ".$_FILES['imagefile']['size']."<br>"; 
echo "Type: ".$_FILES['imagefile']['type']."<br>"; 
echo "Copy Done...."; 
}
} else {
echo "<br><br>";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
}
} else {
echo "<h3><font color=\"#FF0000\">Image must be 35px by 35px (height, width)</font></h3>  
<form action\"\" method=\"post\" name=\"image_upload\" enctype=\"multipart/form-data\">
<input type=\"file\" name=\"imagefile\">
<br>
<input type=\"submit\" name=\"Submit\" value=\"Submit\"> 
</form>";
}
?>

Link to comment
Share on other sites

<?php
$db_host = "****";
$db_user = "****";
$db_pwd = "****";
$db_name = "****";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<html>
<head>
<title>RuneScapez.com :: Items DB Submission Form</title>
</head>
<body>
<p><font size="4" face="Arial, Helvetica, sans-serif"><strong>Items Database Submission 
  Form</strong></font><font size="2" face="Arial, Helvetica, sans-serif"> (Version 
  0.3_alpha)</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif"> 

  <?php
if (!isset($_POST['submit'])) {
?>

  <font color="#666666">* - Required</font></font> </p>
<p><font size="2" face="Arial, Helvetica, sans-serif">Please make sure you delete 
  all Example Text if you are to leave a Field Blank. Try to fill out as many 
  Fields as you can. Please note that the items Database Submission form and the 
  Items Database itself is still under construction; however, please help us by 
  filling in the form as the data will be kept no matter how much we change/ruin 
  the database!</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif">Note From RuneHQ: We can 
  take legal action against anyone found stealing our content. submitted information 
  is Copyrighted to RuneHQ. It's use on other sites is expressly forbidden. Do 
  Not ask if you can use our guides or images, the answer is and always will be 
  NO!</font></p>
<p><em><font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif">This means that you 
  must NOT take information about items from RuneHQ's Database. Please find information 
  yourself; we respect the rights of other Fansites, so please only copy data 
  that stays the same (Such as Examine Info - That isn't copying as it is the 
  same on the Game itself). Please type out things like Notes yourself; do NOT 
  copy notes from RuneHQ. Thank You!</font></em></p>
<p><font size="2" face="Arial, Helvetica, sans-serif"><em>Any Spam Submissions 
  will be deleted without warning. Thank You for Participating!</em></font></p>
  
<form action="" method="post">

  <p><font size="2" face="Arial, Helvetica, sans-serif">Item Name*: 
    <input name="itemname" type="text" size="20" maxlength="20">
    - Such as 'Book of Balance' or 'Banana'<br>
    <br>

    Item Type: 
    <select name="itemtype" id="itemtype">
<option value=""></option>
<option value="Ammo/Projectiles">Ammo/Projectiles</option>
<option value="Armour">Armour</option>
<option value="Books/Scrolls">Books/Scrolls</option>
<option value="Clothing/Appearance">Clothing/Appearance</option>
<option value="Currency/Tokens">Currency/Tokens</option>
<option value="Food/Drink">Food & Drink</option>
<option value="Handy/Tools">Handy/Tools</option>
<option value="Jewellery/Enchanted">Jewellery/Enchanted</option>
<option value="Keys and Thieving">Keys and Thieving</option>
<option value="Magic-Related Items">Magic-Related Items</option>
<option value="Miscellaneous">Miscellaneous</option>
<option value="N/A">N/A</option>
<option value="Potions/Poisons">Potions/Poisons</option>
<option value="Quest Items">Quest Items</option>
<option value="Rare/Discontinued">Rare/Discontinued</option>
<option value="Raw Materials">Raw Materials</option>
<option value="Rewards">Rewards</option>
<option value="Unusable">Unusable</option>
<option value="Weapon">Weapon</option>
    </select>
    - Select an option from the List<br>
    <br>

    Street Price: 
    <input name="streetprice" type="text" size="17" maxlength="17">
    - Number followed by either: 'gp', 'k gp' or 'mil gp'<br>
    <br>

    High Alch Reward/Special Store Sell Price: 
    <input name="highalch" type="text" size="17">
    <br>
    <br>

    Low Alch Reward/General Store Buy Price: 
    <input name="lowalch" type="text" size="17">
    <br>
    <br>

    Members Only?: 
    <select name="memberitem" id="memberitem">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Stackable?: 
    <select name="stackable" id="stackable">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Quest Item?: 
    <select name="quest" id="quest">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Tradable?: 
    <select name="tradable" id="tradable">
      <option value="Yes">Yes</option>
      <option value="No">No</option>
    </select>
    <br>
    <br>

    Item Stat Gain/Loss:<br>
    <textarea name="stats" cols="33" rows="5" wrap="VIRTUAL">Example:
Prayer: +1
Melee: +25
Range: -12</textarea>
    <br>
    <br>

    Requirements to Use/Wear: <br>
    <textarea name="reqtowear" wrap="VIRTUAL">Example:
Need to have completed 'Monkey Madness'</textarea>
    <br>
    <br>

    Used for: <br>
    <textarea name="usedfor" wrap="VIRTUAL">Example:
Melee Fighting.
Slashing Spiders Webs in Wilderness</textarea>
    <br>
    <br>

    Effects the Item has: <br>
    <textarea name="effects" wrap="VIRTUAL">Example:
Poison taking off 2HP every 30 seconds.</textarea>
    <br>
    <br>

    Right Click Options:<br>
    <textarea name="itemoptions" wrap="VIRTUAL">Example:
Eat, Use, Examine, Drop</textarea>
    <br>
    <br>

    Respawn Areas: <br>
    <textarea name="respawnareas" cols="20" rows="3" wrap="VIRTUAL">Example:
Lumbridge Swamp, Near Goblins</textarea>
    <br>
    <br>

    How and Where is the Item Retrieved?:<br>
    <textarea name="wherefound" wrap="VIRTUAL">Example:
Killing the Kalphite Queen or Player Trading</textarea>
    <br>
    <br>

    Notes/Tips: <br>
    <textarea name="notes" cols="45" rows="6" wrap="VIRTUAL"></textarea>
    <br>
    <br>

    Examine Info: 
    <input name="examine" type="text" size="56">
    <br>
    <br>

    Your Username/Nickname: 
    <input name="username" type="text" size="20">
    <br>
    <br>

Item Image: (Please Upload one from your Computer by Clicking 'Browse')

<!-- This is where I want the upload, browse and the remaining text box with the URL to appear. Thanks for your help! -->
<br>
<font color="#FF0000">Image must be 35px by 35px (height, width)</font></h3>
<input type="file" name="imagefile">
</p>

  <p><font size="2" face="Arial, Helvetica, sans-serif">
    <input type="submit" name="submit" value="Submit New Item">
    <input name="reset" type="reset" id="reset" value="Clear Form">
  </font></p>
</form>
<font size="2" face="Arial, Helvetica, sans-serif"> 

<!-- The php code below sends all of the values of the textboxes/select boxes to my MySQL Database, I've added 'imgurl' in there now. -->
<?php
} else {
if ($_FILES['imagefile']['type'] == "image/jpg" || "image/jpeg" || "image/gif" ||  "image/tiff" ||  "image/png" ||  "image/mng" ||  "image/bmp" ||  "image/wbmp"){
	if($width>35 || $height>35){
		die("<font color=\"#FF0000\"><b>Image exceededs image dimension limits.</b></font>");
	} else {
		copy ($_FILES['imagefile']['tmp_name'], "./idb/pictures/".$_FILES['imagefile']['name']) or die ("Could not copy"); 
		$path = "<your domain>/imb/pictures/{$_FILES['imagefile']['name']}";
		echo "<br>"; 
		echo "?><input type=\"text\" name=\"imgurl\" readonly value=\"$path/>";
		echo "Name: ".$_FILES['imagefile']['name']."<br>"; 
		echo "Size: ".$_FILES['imagefile']['size']."<br>";
		echo "Type: ".$_FILES['imagefile']['type']."<br>";
		echo "Copy done...."; 
	}
} else {
	echo "<br><br>";
	echo "Could not copy, wrong filetype (".$_FILES['imagefile']['name'].")<br>";
}


$itemname = $_POST['itemname'];
$itemtype = $_POST['itemtype'];
$streetprice = $_POST['streetprice'];
$highalch = $_POST['highalch'];
$lowalch = $_POST['lowalch'];
$memberitem = $_POST['memberitem'];
$stackable = $_POST['stackable'];
$quest = $_POST['quest'];
$tradable = $_POST['tradable'];
$stats = $_POST['stats'];
$reqtowear = $_POST['reqtowear'];
$effects = $_POST['effects'];
$itemoptions = $_POST['itemoptions'];
$respawnareas = $_POST['respawnareas'];
$wherefound = $_POST['wherefound'];
$notes = $_POST['notes'];
$examine = $_POST['examine'];
$username = $_POST['username'];
$imgurl = $_POST['imgurl'];
mysql_query("INSERT INTO `items` (itemname, itemtype, streetprice, highalch, lowalch, memberitem, stackable, quest, tradable, stats, reqtowear, effects, itemoptions, respawnareas, wherefound, notes, examine, username) VALUES ('$itemname', '$itemtype', '$streetprice', '$highalch', '$lowalch', '$memberitem', '$stackable', '$quest', '$tradable', '$stats', '$reqtowear', '$effects', '$itemoptions', '$respawnareas', '$wherefound', '$notes', '$examine', '$username', '$imgurl')");
echo "Your item has been successfully submitted into the database! Thank you.";
}
?>

</font> 

</body>

</html>

 

Best of luck. (Fixed a couple typos for you too :) )

P.S. You need to edit $path on Ln207 to whatever works for you.

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.