Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 05-20-2007, 5:33 PM   #1
Alfred Molon
 
Alfred Molon's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

This is causing problems in a photo contest application I run on a site
(the uploads don't work properly if the filename contains an apostrophe,
such as for instance St Paul's.jpg). I'm using this for the html form:

<input type="hidden" name="MAX_FILE_SIZE" value="10000000" size="40">
<input name="userfile" type="file">

Files are JPEG images and I'm using this to retrieve the image:

$picname = $_FILES['userfile']['name'];
$tmp_picname = $_FILES['userfile']['tmp_name'];
$pictype = $_FILES['userfile']['type'];
$picsize = $_FILES['userfile']['size'];

What code can I use?
--

Alfred Molon
http://www.molon.de - Photos of Asia, Africa and Europe
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 05-20-2007, 5:33 PM   #2
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

On May 13, 4:36 pm, Alfred Molon <alfred_molonCAN...@yahoo.com> wrote:
> This is causing problems in a photo contest application I run on a site
> (the uploads don't work properly if the filename contains an apostrophe,
> such as for instance St Paul's.jpg). I'm using this for the html form:
>
> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" size="40">
> <input name="userfile" type="file">
>
> Files are JPEG images and I'm using this to retrieve the image:
>
> $picname = $_FILES['userfile']['name'];
> $tmp_picname = $_FILES['userfile']['tmp_name'];
> $pictype = $_FILES['userfile']['type'];
> $picsize = $_FILES['userfile']['size'];
>
> What code can I use?
> --
>
> Alfred Molonhttp://www.molon.de- Photos of Asia, Africa and Europe


this kind of thing indicates either coding bad practise or setup
issues, but can be solved easily by filtering the filenames to remove
all but characters you feel comfortable with.
the manual for preg_replace and ereg_replace contain main examples of
this type of filtering.
$strName = eregi_replace("([^a-zA-Z_\-])",'',$_FILES['userfile']
['name']);
the other way is to investigate why your system doesnt like it, which
requires your code to be posted, and probably your setup details. It
will probably turn out to be a magic quotes / safe mode issue and
possibly some code. Google for XSS, SQL injection and so forth to see
why you should be aware and take care of all strange input from your
users.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #3
Jim Moe
 
Jim Moe's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

Alfred Molon wrote:
>
> $picname = $_FILES['userfile']['name'];
> $tmp_picname = $_FILES['userfile']['tmp_name'];
> $pictype = $_FILES['userfile']['type'];
> $picsize = $_FILES['userfile']['size'];
>

Use double quotes instead?

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #4
Alfred Molon
 
Alfred Molon's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

In article <IuGdnaO5V-cm69rbnZ2dnUVZ_ovinZ2d@giganews.com>, jmm-
list.AXSPAMGN@sohnen-moe.com says...
> Alfred Molon wrote:
> >
> > $picname = $_FILES['userfile']['name'];
> > $tmp_picname = $_FILES['userfile']['tmp_name'];
> > $pictype = $_FILES['userfile']['type'];
> > $picsize = $_FILES['userfile']['size'];
> >

> Use double quotes instead?


How... does that work? You mean perhaps the following?

$picname = $_FILES[''userfile''][''name''];
--

Alfred Molon
http://www.molon.de - Photos of Asia, Africa and Europe
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #5
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

On May 13, 10:45 pm, Alfred Molon <alfred_molonCAN...@yahoo.com>
wrote:
> In article <IuGdnaO5V-cm69rbnZ2dnUVZ_ovin...@giganews.com>, jmm-
> list.AXSPA...@sohnen-moe.com says...
>
> > Alfred Molon wrote:

>
> > > $picname = $_FILES['userfile']['name'];
> > > $tmp_picname = $_FILES['userfile']['tmp_name'];
> > > $pictype = $_FILES['userfile']['type'];
> > > $picsize = $_FILES['userfile']['size'];

>
> > Use double quotes instead?

>
> How... does that work? You mean perhaps the following?
>
> $picname = $_FILES[''userfile''][''name''];
> --
>
> Alfred Molonhttp://www.molon.de- Photos of Asia, Africa and Europe


alfred, i use php uploads with single quotes just fine, it copes with
a large range of characters including single quotes.
you say "the uploads dont work properly" but I am unclear as to what
that means, where does the process fail? I just think it's a coding/
config issue, the actual upload functionality will remain completely
unaffected - if your system is set up properly.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #6
Alfred Molon
 
Alfred Molon's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

In article <1179093340.453709.241100@n59g2000hsh.googlegroups .com>,
matt.farey@gmail.com says...

> alfred, i use php uploads with single quotes just fine, it copes with
> a large range of characters including single quotes.
> you say "the uploads dont work properly" but I am unclear as to what
> that means, where does the process fail? I just think it's a coding/
> config issue, the actual upload functionality will remain completely
> unaffected - if your system is set up properly.


It's a shared host and I can not set the system.

In any case what happens, is that the image will upload and be stored in
the temporary , but then the PHP code will mess up the filename.

For instance, if I upload the file "Al Azhar's mosque Cairo.jpg" (with
the apostrophe), the PHP code will automatically convert the filename to
"Al Azhar\'s mosque Cairo.jpg" (i.e. insert a backslash) and store a
file named "Al Azhar\'s mosque Cairo.jpg" in the temporary directory.

Then for misterious reasons it will convert the filename to "Al Azhar
\\\'s mosque Cairo.jpg" (i.e. insert two more backslashs). This happens
after the filename has been passed as a POST parameter to another
script.

Perhaps I should process the filename with rawurlencode or htmlentities
before passing it as a POST parameter to the other script.
--

Alfred Molon
http://www.molon.de - Photos of Asia, Africa and Europe
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #7
Beauregard T. Shagnasty
 
Beauregard T. Shagnasty's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

In alt.www.webmaster, Alfred Molon wrote:

> For instance, if I upload the file "Al Azhar's mosque Cairo.jpg" (with
> the apostrophe), the PHP code will automatically convert the filename
> to "Al Azhar\'s mosque Cairo.jpg" (i.e. insert a backslash) and store
> a file named "Al Azhar\'s mosque Cairo.jpg" in the temporary
> directory.
>
> Then for misterious reasons it will convert the filename to "Al Azhar
> \\\'s mosque Cairo.jpg" (i.e. insert two more backslashs). This
> happens after the filename has been passed as a POST parameter to
> another script.


Look up htmlentities.

Though it would likely be much easier if you were to strip out all
characters except alpha, numeric, and the underscore prior to storage
(file and database entry). Perhaps replace spaces with underscores.

--
-bts
-Motorcycles defy gravity; cars just suck
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #8
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

On May 13, 11:25 pm, Alfred Molon <alfred_molonCAN...@yahoo.com>
wrote:
> In article <1179093340.453709.241...@n59g2000hsh.googlegroups .com>,
> matt.fa...@gmail.com says...
>
> > alfred, i use php uploads with single quotes just fine, it copes with
> > a large range of characters including single quotes.
> > you say "the uploads dont work properly" but I am unclear as to what
> > that means, where does the process fail? I just think it's a coding/
> > config issue, the actual upload functionality will remain completely
> > unaffected - if your system is set up properly.

>
> It's a shared host and I can not set the system.
>
> In any case what happens, is that the image will upload and be stored in
> the temporary , but then the PHP code will mess up the filename.
>
> For instance, if I upload the file "Al Azhar's mosque Cairo.jpg" (with
> the apostrophe), the PHP code will automatically convert the filename to
> "Al Azhar\'s mosque Cairo.jpg" (i.e. insert a backslash) and store a
> file named "Al Azhar\'s mosque Cairo.jpg" in the temporary directory.
>
> Then for misterious reasons it will convert the filename to "Al Azhar
> \\\'s mosque Cairo.jpg" (i.e. insert two more backslashs). This happens
> after the filename has been passed as a POST parameter to another
> script.
>
> Perhaps I should process the filename with rawurlencode or htmlentities
> before passing it as a POST parameter to the other script.
> --
>
> Alfred Molonhttp://www.molon.de- Photos of Asia, Africa and Europe


this is "magic quotes" a waste of time, and kinda dangerous.
you can use stripslashes to remove the slashes, 2 more come because
once there is one, it is seen by the next function along and gets
preserved, how do you preserve a backslash? you add 2 backslashes, one
to escape the original one, and a second to escape the 2nd to show
that it is to be interpreted as "real"
As I say this is a config issue, you can probably set magic quotes to
off using ini_set, which I recommend, you are then responsible for
filtering and managing user input, but at least it becomes more
predictable.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #9
Good Man
 
Good Man's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

"Beauregard T. Shagnasty" <a.nony.mous@example.invalid> wrote in
news:0KM1i.15246$yM2.5488@bgtnsc04-news.ops.worldnet.att.net:


> Though it would likely be much easier if you were to strip out all
> characters except alpha, numeric, and the underscore prior to storage
> (file and database entry). Perhaps replace spaces with underscores.



I agree. Here's what I use to "clean" the filenames of all uploaded
files:


function cleanFile ($filename) { //clean up the file name

$filename = str_replace(" ","_",$filename);
$filename = str_replace("\\","",$filename);
$filename = str_replace("/","",$filename);
$filename = str_replace("|","_",$filename);
$filename = str_replace("'","",$filename);
$filename = str_replace("\"","",$filename);
$filename = str_replace("","",$filename);
$filename = str_replace("`","",$filename);
$filename = str_replace("*","",$filename);
$filename = str_replace("$","",$filename);
$filename = str_replace("%","percent",$filename);
$filename = str_replace("^","",$filename);
$filename = str_replace("!","",$filename);
$filename = str_replace("@","",$filename);
$filename = str_replace("?","",$filename);
$filename = str_replace(":","",$filename);
$filename = str_replace(";","",$filename);
$filename = str_replace(",","",$filename);
$filename = str_replace("<","",$filename);
$filename = str_replace(">","",$filename);

$filename = strtolower($filename);
return $filename;

}
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #10
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

On May 14, 7:09 pm, Good Man <h...@letsgo.com> wrote:
> "Beauregard T. Shagnasty" <a.nony.m...@example.invalid> wrote innews:0KM1i.15246$yM2.5488@bgtnsc04-news.ops.worldnet.att.net:
>
> > Though it would likely be much easier if you were to strip out all
> > characters except alpha, numeric, and the underscore prior to storage
> > (file and database entry). Perhaps replace spaces with underscores.

>
> I agree. Here's what I use to "clean" the filenames of all uploaded
> files:
>
> function cleanFile ($filename) { //clean up the file name
>
> $filename = str_replace(" ","_",$filename);
> $filename = str_replace("\\","",$filename);
> $filename = str_replace("/","",$filename);
> $filename = str_replace("|","_",$filename);
> $filename = str_replace("'","",$filename);
> $filename = str_replace("\"","",$filename);
> $filename = str_replace("","",$filename);
> $filename = str_replace("`","",$filename);
> $filename = str_replace("*","",$filename);
> $filename = str_replace("$","",$filename);
> $filename = str_replace("%","percent",$filename);
> $filename = str_replace("^","",$filename);
> $filename = str_replace("!","",$filename);
> $filename = str_replace("@","",$filename);
> $filename = str_replace("?","",$filename);
> $filename = str_replace(":","",$filename);
> $filename = str_replace(";","",$filename);
> $filename = str_replace(",","",$filename);
> $filename = str_replace("<","",$filename);
> $filename = str_replace(">","",$filename);
>
> $filename = strtolower($filename);
> return $filename;
>
> }


the trouble with this kind of blacklist banning is that it allows
encoding and otherforms of clever attack.
better to use a whitelist.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: , , ,




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

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

vB 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
Uploading by FTP and line ending settings dorayme PHP 1 05-20-2007 5:33 PM
Uploading files with IXR (XMLRPC) soraya_soch@yahoo.com PHP 0 05-20-2007 5:33 PM
Uploading files with IXR (XMLRPC) soraya_soch@yahoo.com PHP 0 05-20-2007 5:33 PM
bin & cue files , spot516 Computer Consoles 1 05-08-2007 4:55 AM
Does anyone know how to make .dll files? Mattster Windows 8 04-05-2006 12:25 AM


Featured Websites




All times are GMT +1. The time now is 2:08 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

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 86 87 88 89 90 91 92 93 94 95 96 97 98