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";
} else {
print "<p>photo not found :(</p>";
$hasPhoto = "0";
}
unlink($registrationPhoto);
}
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)
{
$text = ereg_replace("її:alpha:]]+://ї^<>ї:space:]]+її:alnum:]/]", "<a href="\0" target="_blank">\0</a>", $text);
$text = ereg_replace("<aї^>]+href *= *"(ї^ ]+)"*>", "<a href="\1 target="_blank">", $text);
$text = ereg_replace("ї_a-zA-z0-9-]+(.ї_a-zA-z0-9-]+)*@" . "ї_a-zA-z0-9-]+(.їa-zA-z]{1,3})+" . "?*їsubject=ї_a-zA-z0-9-]+]*&*їbody=ї_a-zA-z0-9-]+]*", "<a href="mailto:\0">\0</a>", $text);
return nl2br($text);
}
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) {
// PAD WITH A SPACE
$data = " " . $data;
// STRIP TAGS
$data = strip_tags($data);
$data = eregi_replace("\їb\](.*)(\ї/b\])", "<b>\\1</b>", $data);
$data = eregi_replace("\їi\](.*)(\ї/i\])", "<i>\\1</i>", $data);
$data = eregi_replace("\їu\](.*)(\ї/u\])", "<u>\\1</u>", $data);
$data = eregi_replace("\їcolor=(ї#a-fA-F0-9]{7}|їa-zA-Z]*)\](.*)\ї/color\]",
"<span style="color:\\1">\\2</span>", $data);
$data = eregi_replace("\їimg\](ї-a-zA-Z0-9@:%_\+.~#?&//=]+)\ї/img\]",
"<img src="\\1" alt="" border="0" />", $data);
$data = eregi_replace('(її:space:]()ї{}])(www.ї-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2" target="_blank">\\2</a>', $data);
$data = eregi_replace('(її:space:]()ї{}])(http://ї-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="\\2" target="_blank">\\2</a>', $data);
$data = eregi_replace("\їurl\](їwww.]+їa-zA-Z0-9@:%_\+.~#?&//=]+)\ї/url\]",
"<a href="http://\\1" target="_blank">\\1</a>", $data);
$data = eregi_replace("\їurl\](їa-zA-Z]+ї:]+їa-zA-Z0-9@:%_\+.~#?&//=]+)\ї/url\]",
"<a href="\\1" target="_blank">\\1</a>", $data);
$data = eregi_replace("\їurl=(їwww.]+їa-zA-Z0-9@:%_\+.~#?&//=]+)\](.*)\ї/url\]",
"<a href="http://\\1" target="_blank">\\2</a>", $data);
$data = eregi_replace("\їurl=(їa-zA-Z]+ї:]+їa-zA-Z0-9@:%_\+.~#?&//=]+)\](.*)\ї/url\]",
"<a href="\\1" target="_blank">\\2</a>", $data);
$data = str_replace("\n", "\n<br /> ", $data);
return trim($data);
}
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?