[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 12-24-2005, 07:15 PM   #1 (permalink)
NamePros Member
 
Join Date: Dec 2005
Posts: 186
0.00 NP$ (Donate)

chronic will become famous soon enoughchronic will become famous soon enough


PHP Help

I need help making this script work. For some reason, it won't let me upload the files. I took this script from a thread on here and modified it but it still doesn't work. Any ideas? The error says it is on line 25 and I have no clue what might be wrong there.

PHP Code:
<?php
if($_POST[finshed] == '1') {
$upload_dir = "images/";
$max_size = 1024000;

if(
is_uploaded_file($_FILES['image']['tmp_name']))
{
  
$size = $_FILES['image']['size'];

  if(
$size > $max_size)
  {
    echo
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
    exit();
  }
  
$filename = $_FILES['image']['name'];

  if(
file_exists($upload_dir.$filename))
  {
    echo
"Error: The file named <b>$filename</b> already exists.";
    exit();
  }

  if(
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$filename))
  {
    echo
"Your image uploaded successfully!<br />
    <input type=\"text\" onClick='highlight(this);' style=\"width: 500px\" size=\"70\" value=\"[URL=http://atyourhost.com][IMG]http://www.atyourhost.com/\".$upload_dir.$filename.\"[/IMG][/URL]\" /> Forum Hotlink 1<br /><br />
<input type=\"text\" onClick='highlight(this);' style=\"width: 500px\" size=\"70\" value=\"[url=http://imageshack.us][img=http://www.atyourhost.com/\".$upload_dir.$filename.\"][/url]\" /> Forum Hotlink 2<br /><br />
<input type=\"text\" onClick='highlight(this);' style=\"width: 500px\" size=\"70\" value=\"http://www.atyourhost.com/\".$upload_dir.$filename.\"\" /> Direct Link<br /><br />"";
    exit();
  }
  else
  {
    echo "
There was a problem uploading your file. Please try again.";
    exit();
  }
}
}else{
?>
<html>
<head>
<title>Image upload</title>
</head>
<body>

<form action="
upload.php" method="post" enctype="multipart/form-data">
<input type="
hidden" name="finshed" value="1">
Image: <input type="
file" name="image" size="20">&nbsp;
<input type="
submit" name="submit" value="Upload">
</form>
</body>
</html>
<?php } ?>
__________________
DNFind.net - For sale, PM me.
chronic is offline  
Old 12-24-2005, 07:41 PM   #2 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Try this:

PHP Code:
<?php
if($_POST[finshed] == '1') {
$upload_dir = "images/";
$max_size = 1024000;

if(
is_uploaded_file($_FILES['image']['tmp_name']))
{
  
$size = $_FILES['image']['size'];

  if(
$size > $max_size)
  {
    echo
"File Too Large. File must be no larger than <b>$max_size</b> bytes.";
    exit();
  }
  
$filename = $_FILES['image']['name'];

  if(
file_exists($upload_dir.$filename))
  {
    echo
"Error: The file named <b>$filename</b> already exists.";
    exit();
  }

  if(
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$filename))
  {
    echo
"Your image uploaded successfully!<br />
    <input type=\"text\" onClick='highlight(this);' style=\"width: 500px\" size=\"70\" value=\"[URL=http://atyourhost.com][IMG]http://www.atyourhost.com/"
.$upload_dir.$filename."[/IMG][/URL]\" /> Forum Hotlink 1<br /><br />
    <input type=\"text\" onClick='highlight(this);' style=\"width: 500px\" size=\"70\" value=\"[url=http://imageshack.us][img=http://www.atyourhost.com/"
.$upload_dir.$filename."][/url]\" /> Forum Hotlink 2<br /><br />
    <input type=\"text\" onClick='highlight(this);' style=\"width: 500px\" size=\"70\" value=\"http://www.atyourhost.com/"
.$upload_dir.$filename."\" /> Direct Link<br /><br />";
    exit();
  }
  else
  {
    echo
"There was a problem uploading your file. Please try again.";
    exit();
  }
}
}else{
?>
<html>
<head>
<title>Image upload</title>
</head>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="finshed" value="1">
Image: <input type="file" name="image" size="20">&nbsp;
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
<?php } ?>
__________________
Eric is offline  
Old 12-24-2005, 08:16 PM   #3 (permalink)
NamePros Member
 
Join Date: Dec 2005
Posts: 186
0.00 NP$ (Donate)

chronic will become famous soon enoughchronic will become famous soon enough


Still doesn't work.

Code:
Warning: move_uploaded_file(uploaded/header.gif): failed to open stream: No such file or directory in /home/vergear/public_html/upload.php on line 25

Warning: move_uploaded_file(): Unable to move '/tmp/phpaKIz2c' to 'uploaded/header.gif' in /home/vergear/public_html/upload.php on line 25
There was a problem uploading your file. Please try again.
I will check back later to see if if anyone has some updates for me.

If someone completely fixes it, I may give you a free domain name.
__________________
DNFind.net - For sale, PM me.
chronic is offline  
Old 12-24-2005, 08:26 PM   #4 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
You sure you have the uploaded folder created, plus CHMOD'ed to 777?
__________________
Eric is offline  
Old 12-24-2005, 09:15 PM   #5 (permalink)
NamePros Member
 
Join Date: Dec 2005
Posts: 186
0.00 NP$ (Donate)

chronic will become famous soon enoughchronic will become famous soon enough


Yeah. I will double check it though.

Ah, it works now. But when I upload an image, it doesn't display it properly in the boxes.

http://atyourhost.com/upload.php < Try it yourself and look at the result
__________________
DNFind.net - For sale, PM me.
chronic is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
Great Scripts for Sale With Resale Rights! Zeeble Scripts For Sale 20 01-04-2006 01:39 AM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 04:32 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85