Page 1 of 1

File upload - specifically an image in GIF format

Posted: Tue Aug 20, 2002 9:35 am
by Rebajas
I have just written a script to upload a image and rename in based on the the registered users Nickname. Unfortunately all my hard work was for nothing as it doesn't work :(

The code i have included in the site is below:

Code: Select all

if ($registrationPhoto) {
		if (copy($registrationPhoto, "/home/876/Rebajas2/images/profiles/".$registrationNickname.".gif")) {
			print "<p><img src="/images/".$registrationNickname.".gif" alt="".$registrationNickname."" /></p>";
			$hasPhoto = "1";
		&#125; else &#123;
			print "<p>photo not found :(</p>";
			$hasPhoto = "0";
		&#125;
		unlink($registrationPhoto);
	&#125;
If anybody has any comments on the code that might resolve the situation, they'd be well recieved :)

Cheers,

Rebajas.

Posted: Tue Aug 20, 2002 10:34 am
by theChosen
Things that might go wrong (specify exactly your problem for future assistance):
1. register_globals is off so $_POST['registrationPhoto'] is set instead of $registrationPhoto; rule applies for all post vars
2. the script does not have writing access on /home/876/Rebajas2/images/profiles/
3. TRY changing

Code: Select all

print "<p><img src="/images/".$registrationNickname.".gif" alt="".$registrationNickname."" /></p>";
WITH

Code: Select all

print "<p><img src="/images/profiles/".$registrationNickname.".gif" alt="".$registrationNickname."" ></p>";
4. observation: you don't have to explicitly specify unlink as php does that automaticaly on script end (deleting of temporary files)

Posted: Tue Aug 20, 2002 2:47 pm
by hex
What I'm trying to do is provide a function to parse the output of a database. By this I mean do such things as nl2br() and replace URLs with links.

However, I'm allowing the use of <a> tags in the input (stripped down to only have the href attrtibute), and so I need to only replace/parse the URLs that are not already in <a> tags.

This is what I have so far:

Code: Select all

function parseHTML($text) 
    &#123; 
        $text = ereg_replace("&#1111;&#1111;:alpha:]]+://&#1111;^<>&#1111;:space:]]+&#1111;&#1111;:alnum:]/]", "<a href="\0" target="_blank">\0</a>", $text); 
        $text = ereg_replace("<a&#1111;^>]+href *= *"(&#1111;^ ]+)"*>", "<a href="\1 target="_blank">", $text); 
        $text = ereg_replace("&#1111;_a-zA-z0-9-]+(.&#1111;_a-zA-z0-9-]+)*@" . "&#1111;_a-zA-z0-9-]+(.&#1111;a-zA-z]&#123;1,3&#125;)+" . "?*&#1111;subject=&#1111;_a-zA-z0-9-]+]*&*&#1111;body=&#1111;_a-zA-z0-9-]+]*", "<a href="mailto:\0">\0</a>", $text); 
        return nl2br($text); 
    &#125;
I tried such things as [^href], (^href) etc but to no avail. Any help appreciated!

Cheers people.

Posted: Tue Aug 20, 2002 3:24 pm
by hob_goblin
here is what i use:

Code: Select all

function parseCode($data) &#123;
   // PAD WITH A SPACE
   $data = " " . $data; 
   // STRIP TAGS
   $data = strip_tags($data);
  
   $data = eregi_replace("\&#1111;b\](.*)(\&#1111;/b\])", "<b>\\1</b>", $data);
   $data = eregi_replace("\&#1111;i\](.*)(\&#1111;/i\])", "<i>\\1</i>", $data);
   $data = eregi_replace("\&#1111;u\](.*)(\&#1111;/u\])", "<u>\\1</u>", $data);

   $data = eregi_replace("\&#1111;color=(&#1111;#a-fA-F0-9]&#123;7&#125;|&#1111;a-zA-Z]*)\](.*)\&#1111;/color\]",
   "<span style="color:\\1">\\2</span>", $data);
   
   $data = eregi_replace("\&#1111;img\](&#1111;-a-zA-Z0-9@:%_\+.~#?&//=]+)\&#1111;/img\]",
   "<img src="\\1" alt="" border="0" />", $data);


   $data = eregi_replace('(&#1111;&#1111;:space:]()&#1111;&#123;&#125;])(www.&#1111;-a-zA-Z0-9@:%_\+.~#?&//=]+)',
   '\\1<a href="http://\\2" target="_blank">\\2</a>', $data);

   $data = eregi_replace('(&#1111;&#1111;:space:]()&#1111;&#123;&#125;])(http://&#1111;-a-zA-Z0-9@:%_\+.~#?&//=]+)',
  '\\1<a href="\\2" target="_blank">\\2</a>', $data); 

   $data = eregi_replace("\&#1111;url\](&#1111;www.]+&#1111;a-zA-Z0-9@:%_\+.~#?&//=]+)\&#1111;/url\]",
   "<a href="http://\\1" target="_blank">\\1</a>", $data);

   $data = eregi_replace("\&#1111;url\](&#1111;a-zA-Z]+&#1111;:]+&#1111;a-zA-Z0-9@:%_\+.~#?&//=]+)\&#1111;/url\]",
   "<a href="\\1" target="_blank">\\1</a>", $data);

   $data = eregi_replace("\&#1111;url=(&#1111;www.]+&#1111;a-zA-Z0-9@:%_\+.~#?&//=]+)\](.*)\&#1111;/url\]",
   "<a href="http://\\1" target="_blank">\\2</a>", $data);

   $data = eregi_replace("\&#1111;url=(&#1111;a-zA-Z]+&#1111;:]+&#1111;a-zA-Z0-9@:%_\+.~#?&//=]+)\](.*)\&#1111;/url\]",
   "<a href="\\1" target="_blank">\\2</a>", $data);

   $data = str_replace("\n", "\n<br />&nbsp;", $data);     
   
   return trim($data); 
&#125;
i do not reccommend accepting anchor tags because i could easily do:

<a onClick="window.close();" href="#">something</a>

Posted: Wed Aug 21, 2002 5:02 am
by Rebajas
theChosen wrote:Things that might go wrong (specify exactly your problem for future assistance):
1. register_globals is off so $_POST['registrationPhoto'] is set instead of $registrationPhoto; rule applies for all post vars
2. the script does not have writing access on /home/876/Rebajas2/images/profiles/
3. TRY changing

Code: Select all

print "<p><img src="/images/".$registrationNickname.".gif" alt="".$registrationNickname."" /></p>";
WITH

Code: Select all

print "<p><img src="/images/profiles/".$registrationNickname.".gif" alt="".$registrationNickname."" ></p>";
4. observation: you don't have to explicitly specify unlink as php does that automaticaly on script end (deleting of temporary files)
Hiya,

Thanks for the help, with regard your comments i'm not sure any of those are the problem aside from number '3'. I have fixed the typo that should have displayed the image :? but the others seem to be fine.

1. All the other variables are referenced by $registrationXxxx and have worked with no problems. Is this an issue specific to file uploads?

2. The directory has full access (777). I'm loathed to admit that i have managed to write things to this directory before but have since lost the code due to changes made having not noticed the typo in '3'.

3. See above ;)

4. Does it do any harm with that there?

If you have any other ideas or need more information please let me know. The only other thing i can add is the fact that i get different errors depending on whether I view using IE4 or IE6?!?!

Cheers.

Posted: Wed Aug 21, 2002 10:58 am
by theChosen
What is/are the exact error/s?