LinuxQuestions.org
Visit Jeremy's Blog.
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 04-19-2010, 10:26 PM   #1
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
PHP (ick!) question.


When i do a php file upload, the file is not actually saved.
example: ,<removed link so people dont upload crap>
If i upload a file, it does not appear on my server, and yes i a serving this on 'dows and no i dont want a security lecture.
PHP Code:
<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo 
"Error: " $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo 
"Upload: " $_FILES["file"]["name"] . "<br />";
  echo 
"Type: " $_FILES["file"]["type"] . "<br />";
  echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo 
"Stored in: " $_FILES["file"]["tmp_name"];
  }
?>
That is from w3's website FYI.
LOG:
Code:
07-Apr-2010 00:14:02] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[07-Apr-2010 17:17:27] PHP Warning:  Unexpected character in input:  ''' (ASCII=39) state=1 in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum\cache\ctpl_admin_acp_main.html.php on line 257

[07-Apr-2010 17:17:27] PHP Parse error:  syntax error, unexpected $end, expecting ']' in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum\cache\ctpl_admin_acp_main.html.php on line 257

[08-Apr-2010 04:03:18] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[08-Apr-2010 04:03:19] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[08-Apr-2010 04:03:22] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[11-Apr-2010 14:47:38] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[11-Apr-2010 17:52:49] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[11-Apr-2010 18:01:07] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[11-Apr-2010 19:45:43] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[11-Apr-2010 19:55:17] PHP Notice:  Undefined index:  fixed in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 49

[12-Apr-2010 18:07:32] PHP Notice:  Undefined variable: id in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\comment.php on line 32

[16-Apr-2010 15:03:34] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum\viewtopic.php on line 1031

[17-Apr-2010 15:32:54] PHP Notice:  Undefined variable: title in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 51

[17-Apr-2010 15:32:54] PHP Notice:  Undefined variable: id in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 51

[17-Apr-2010 15:32:54] PHP Notice:  Undefined variable: status in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 52

[17-Apr-2010 15:32:54] PHP Notice:  Undefined variable: poster in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 59

[17-Apr-2010 15:32:54] PHP Notice:  Undefined variable: version in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 60

[17-Apr-2010 15:32:54] PHP Notice:  Undefined variable: date in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 61

[17-Apr-2010 15:32:54] PHP Notice:  Undefined variable: description in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test\read_bug.php on line 62

[18-Apr-2010 15:39:23] PHP Fatal error:  SQL ERROR [ mysql4 ]<br /><br />Got error 28 from storage engine [1030]<br /><br />SQL<br /><br />SHOW COLUMNS FROM phpbb_config<br /><br />BACKTRACE<br /><div style="font-family: monospace;"><br /><b>FILE:</b> includes/db/mysql.php<br /><b>LINE:</b> 174<br /><b>CALL:</b> dbal-&gt;sql_error()<br /><br /><b>FILE:</b> install.unu/database_update.php<br /><b>LINE:</b> 261<br /><b>CALL:</b> dbal_mysql-&gt;sql_query()<br /></div><br /> in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\forum\includes\db\dbal.php on line 697

[19-Apr-2010 19:42:35] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 2

[19-Apr-2010 19:42:35] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 8

[19-Apr-2010 19:42:35] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 9

[19-Apr-2010 19:42:35] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 10

[19-Apr-2010 19:42:35] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 11

[19-Apr-2010 19:43:04] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 2

[19-Apr-2010 19:43:04] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 8

[19-Apr-2010 19:43:04] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 9

[19-Apr-2010 19:43:04] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 10

[19-Apr-2010 19:43:04] PHP Notice:  Undefined index:  file in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin.upload\upload_file.php on line 11

Last edited by smeezekitty; 04-20-2010 at 01:03 AM. Reason: Removed link so people dont upload crap to my server
 
Old 04-19-2010, 11:35 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I see no real issues with the code you have presented, but I did notice that the 2 fatal and 1 parse errors are on wildly
differently numbered lines. Maybe we should be looking at that code?
 
Old 04-19-2010, 11:55 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
No, that was back when i debugging something else.
 
Old 04-20-2010, 12:12 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
first you may want to look at the isset() function.
secondly what happens when you var_dump the $_FILES variable?
 
Old 04-20-2010, 12:26 AM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
with var_dump:
Code:
array(1) { ["file"]=>  array(5) { ["name"]=>  string(9) "PIANO.SND" ["type"]=>  string(11) "audio/basic" ["tmp_name"]=>  string(27) "C:\Windows\Temp\php7EDE.tmp" ["error"]=>  int(0) ["size"]=>  int(32640) } } Upload: PIANO.SND
Type: audio/basic
Size: 31.875 Kb
Stored in: C:\Windows\Temp\php7EDE.tmp
 
Old 04-20-2010, 12:33 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
That would indicate the the file has uploaded, so now you need to move it from the temp location to where it is you want to store it on the server. This is done by using the move_uploaded_file() function.
 
Old 04-20-2010, 12:45 AM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
move_uploaded_file($_FILES["file"]["name"], 'F:/uploaded.f');
Like that?
 
Old 04-20-2010, 01:01 AM   #8
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Not quite, the first argument would be the temp file name the second will be the file location, in which you would normally provide the directory and use the file name from the uploaded file.

You do of course need to be careful with that to ensure that you don't overwrite any files you wish to keep.
 
Old 04-20-2010, 01:02 AM   #9
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
move_uploaded_file($_FILES["file"]["tmp_path"], 'F:/uploaded.f');
solved it.
 
  


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
PHP question mussarath Programming 1 03-10-2010 03:12 PM
new to php, have a noob php question! starkes Programming 3 09-12-2008 05:39 PM
PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work gtrawoger Linux - Software 3 12-21-2005 06:51 AM
broke stuff with CHMOD...ick Dodge This Linux - Software 16 08-10-2003 04:31 PM
php question philfighter Programming 3 01-30-2002 10:11 PM

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

All times are GMT -5. The time now is 03:42 AM.

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