USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

[Resolved] A PHProblem

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
d_riordan
Member


Joined: 08 Jan 2024
Posts: 245
Location: Leominster, Massachusetts, U.S.A.

PostPosted: Wed Jul 08, 2024 7:21 pm    Post subject: [Resolved] A PHProblem Reply with quote

So I'm playing with PHP and I've gotten stuck when it comes to uploading files to the server (which is localhost in this case). I've developed a simple script to eliminate as many variables as I can in the hopes of narrowing down the problem. The code looks like this:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>file upload test</title>
</head>
<body>
<form name="form" enctype="multipart/form-data" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" />
   <input type="hidden" name="MAX_FILE_SIZE" value="32768" />
   <input type="file" id="file" name="file" />
   <input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])) {
   echo "File Name: " . $_FILES['file']['name'] . '<br>' .
   "File Type: " . $_FILES['file']['type'] . '<br>' .
   "File Size: " . $_FILES['file']['size'] . '<br>' .
   "Temp Name: " . $_FILES['file']['tmp_name'] . '<br>' .
   "ErrorCode: " . $_FILES['file']['error'];
}
?>
</body>
</html>


To make things easy to post here, I've done my browsing in lynx. Firefox gives the same behaviour, so I don't believe that the problem is browser related.

In lynx, page originally displays like this:

Quote:

____________________ Submit


I enter a file name in the space provided (say /home/myusername/Pictures/54.png) and page displays like:

Quote:

____________________ Submit
File Name: 54.png
File Type: image/png
File Size: 438
Temp Name: /tmp/phpdb7xei
ErrorCode: 0


But, look for the file in /tmp

Code:
 ls -lta


and no new file is there. The time-stamp for /tmp has been updated though.

The directives in the 'File Uploads' section of /etc/php5/apache2/php.ini are set as follows:

Code:
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M


I think the above directives are OK for this test.

No doubt I've overlooked something incredibly simple. Please point out what a fool I am so that I can go on with my learning.

Thanks for looking.



_________________
*buntu 8.04


Last edited by d_riordan on Thu Jul 09, 2024 1:35 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
DocZayus
Ultimate Member


Joined: 15 Feb 2024
Posts: 2199
Location: Fredericton, New Brunswick

PostPosted: Thu Jul 09, 2024 1:08 am    Post subject: Reply with quote

Nowhere in your code are you moving the uploaded file to your uploads folder....



_________________
Sabayon
Vista
Back to top
View user's profile Send private message Visit poster's website
DocZayus
Ultimate Member


Joined: 15 Feb 2024
Posts: 2199
Location: Fredericton, New Brunswick

PostPosted: Thu Jul 09, 2024 1:09 am    Post subject: Reply with quote

check here for an example:

http://www.tizag.com/phpT/fileupload.html



_________________
Sabayon
Vista
Back to top
View user's profile Send private message Visit poster's website
d_riordan
Member


Joined: 08 Jan 2024
Posts: 245
Location: Leominster, Massachusetts, U.S.A.

PostPosted: Thu Jul 09, 2024 1:35 pm    Post subject: Reply with quote

Ok, I'm a fool.

I had been using the 'move_uploaded_file()' function previously, but had been getting errors like:
Quote:
Warning: move_uploaded_file(images/54.png) [function.move-uploaded-file]: failed to open stream: Permission denied in /var/www/php/upload.html on line 28
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpamVyIZ' to 'images/54.png' in /var/www/php/upload.html on line 28

So, I omitted the function in an effort to simplify the code. I was under the impression that an uploaded file would be written to /tmp and left there to deal with later, and began focusing on that 'issue'.

I was also under the impression that I had set the permissions on the target directory to 777. Oops! I was wrong about that.

Using the move_uploaded_file() function with the proper permissions on the target directory is working just fine.

I still have one question though. No file ever appeared in /tmp. Is the file being uploaded as it should, then deleted as soon as the code is finished executing? That would explain the updated timestamp on /tmp AND the fact that no new file existed there, but my reading had suggested that the file might stay there for a while.

As I originally suspected, it turned out to be something very simple. Thanks for making me take a second look.



_________________
*buntu 8.04
Back to top
View user's profile Send private message Visit poster's website
DocZayus
Ultimate Member


Joined: 15 Feb 2024
Posts: 2199
Location: Fredericton, New Brunswick

PostPosted: Mon Jul 20, 2024 1:33 am    Post subject: Reply with quote

TMP is only a temporary directory.
Nothing is supposed to actually stay there, it's just a transition area.
It acts like anything stored in your RAM or your SWAP.



_________________
Sabayon
Vista
Back to top
View user's profile Send private message Visit poster's website
d_riordan
Member


Joined: 08 Jan 2024
Posts: 245
Location: Leominster, Massachusetts, U.S.A.

PostPosted: Tue Jul 21, 2024 1:14 pm    Post subject: Reply with quote

I knew tmp was temporary, but I'd always envisioned it as 'short term parking'. Now I see it's often more like 'curb side drop off'.

Thanks for the help.



_________________
*buntu 8.04
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse