LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-09-2007, 02:45 PM   #1
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Rep: Reputation: 30
Paranormal Phenomena with PHP and uploader script


Hi all

I wanted to write a script that uploads and then resizes a picture into 2 different sizes. The script works but not in all cases and I can't find a common thing between the cases. Here is the script:
PHP Code:
    function upload($imgName$imgTemp){                        
        
$img $imgName;                        
        
$dest strtolower("../uploads/".$imgName);                                                                                
        
$stem strtolower(substr($imgName0strrpos($imgName".")));                
        
move_uploaded_file($imgTemp$dest);
        
$sql_path strtolower("uploads/".$imgName);
        
$ret = array($dest$sql_path$stem);        
        return 
$ret;        
    } 
I call this function by:
uploade($_FILES['pic']['name'], $_FILES['pic']['tmp_name'];
In most cases the script works and uploads the file but sometimes it just quit working. It does the thing repeatedly with a file called: 1.jpg
Edit:
the thing that i just noticed is that there is not tmp_name for $_FILES['pic']. Was the upload unsuccessful<
Any thoughts?

Last edited by vargadanis; 10-09-2007 at 02:51 PM. Reason: more info
 
Old 10-09-2007, 03:50 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I believe that the $_FILES global variable holds information about any upload error.
Also there is a size limit to upload set in the php.ini
 
Old 10-09-2007, 04:16 PM   #3
Ome_Roel
LQ Newbie
 
Registered: Sep 2007
Posts: 9

Rep: Reputation: 1
It does the thing repeatedly with a file called: 1.jpg

$stem = strtolower(substr($imgName, 0, strrpos($imgName, ".")))

Is it true that var $stem becomes "1", maybe $stem became a boolean.

Offcourse not shore if this will cause any problems:-(

Yours kindly Ome_Roel
 
Old 10-10-2007, 07:32 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

PHP Code:
<?php
$imgName 
"1.jpg";
$stem strtolower(substr($imgName0strrpos($imgName".")));
var_dump($stem);
?>
Result:
Quote:
string(1) "1"
So if it's changed into a boolean, at least that's not in the section you posted. Maybe later when you put it in the database?

But another more important thing: It looks to me like you are not filtering input before you use it. What if I upload a picture called "../../../somefile"? Any web user could place files all over your server and overwrite any file the Apache web user can overwrite. Even if you cant upload files with such a filename in most browsers, it doesn't mean it's impossible.

A simple
$imgName = BaseName($imgName);
would fix it.

Another approach would be to not use the filenames the user specifies in the filesystem at all, but use an ID or something instead. You can then simply store the filename in the database if you need it, and if you just need the filename in the filesystem, it will be something like "../upload/$id".

It's a bit safer that way. Don't trust users to provide an extension like ".jpg" to filenames (not all do), and if they do provide an extension, it could be very wrong. And some people use weird unicode characters or questions marks and such in filenames, so you could end up with very strange filenames in the filesystem.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Paranormal portal relies on open source to collect UFO info LXer Syndicated Linux News 0 04-03-2007 08:16 AM
php uploader script probleme hua Programming 6 02-01-2007 11:00 PM
LXer: Title: PHP/MySQL Classifieds Script AddAsset1.php Script Insertion LXer Syndicated Linux News 0 07-02-2006 06:21 PM
Simplest photograph uploader, editor, and album General Linux - Software 3 11-17-2005 05:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration