Lunarpages Web Hosting Forum

Author Topic: Uploading Files with PHP.  (Read 1712 times)

Offline Üripides

  • Spacescooter Operator
  • *****
  • Posts: 40
    • http://www.corvettepalace.com
Uploading Files with PHP.
« on: January 11, 2004, 08:55:41 PM »
Hi, i have been up and down this forum and only found one issue dealing with uploading files with PHP. If possible i would like to know if anyones sees my errors! Is what i have  disallowed due to security reasons? Is there a solution that someone has...Most helpful if you do!~

When i run this script i get "Warning: move_uploaded_file(/home/*****/public_html/******/*******/testImage.gif): failed to open stream: Permission denied" BLAH BLAH....Im not a total newbie and realize this shouldnt be soo difficult of a task. can anyone shed some light as to why i would be getting this error??


Code: [Select]
<?php 
  
//Define some variables 
      
$dir "path/where/you/want/to/upload/files/"//Change this to the correct dir 
    //MIME types to allow, Gif, jpeg, zip &#58;&#58;Edit this to your liking 
      
$types = array&#40;"image/gif","image/pjpeg","application/x-zip-compressed"&#41;; 
    
//Check to determine if the submit button has been pressed 
    
if&#40;isset&#40;$_POST['submit'&#93;&#41;&#41;&#123; 

//Shorten Variables 
     
$tmp_name $_FILES['upload'&#93;['tmp_name'&#93;; 
     
$new_name $_FILES['upload'&#93;['name'&#93;; 



//Check MIME Type 
    
if &#40;in_array&#40;$_FILES['upload'&#93;['type'&#93;, $types&#41;&#41;&#123; 
      
             
                  
      
         //Move file from tmp dir to new location 

        
move_uploaded_file&#40;$tmp_name,$dir . $new_name&#41;; 
          
        
echo "&#123;$_FILES['upload'&#93;['name'&#93;&#125; was uploaded sucessfully!";                  
              
           
          
    &
#125;else&#123; 
          
      
    //Print Error Message 

          
    
echo "<small>File <strong><em>&#123;$_FILES['upload'&#93;['name'&#93;&#125;</em></strong> Was Not Uploaded!</small><br />"
     
    
//Debug 
   
$name =  $_FILES['upload'&#93;['name'&#93;; 
   
$type =    $_FILES['upload'&#93;['type'&#93;; 
   
$size =    $_FILES['upload'&#93;['size'&#93;; 
   
$tmp =     $_FILES['upload'&#93;['name'&#93;; 
    
   
echo "Name&#58; $name<br/ >Type&#58; $type<br />Size&#58; $size<br />Tmp&#58; $tmp"
             
    &
#125; 
      
    
&#125; 
      
      
else&#123; 
      
      
    
echo 'Could Not Upload Files'
      
&
#125; 
        
?>

         
    <form action="<?php echo $_SERVER['PHP_SELF'&#93;; ?>" method="post" enctype="multipart/form-data">
     
      <fieldset>
              <legend>Upload Files</legend>
           
               
                   
          <input type="file" name="upload" />
</fieldset>
<input type="submit" name="submit" value="Upload Files" />
</form>





Thanks in advanced!

M

Offline artayd2

  • Galactic Royalty
  • *****
  • Posts: 378
    • http://www.thundercats-hockey.com
Uploading Files with PHP.
« Reply #1 on: January 11, 2004, 09:12:10 PM »
is the folder you are writing to , writeable?

Offline Üripides

  • Spacescooter Operator
  • *****
  • Posts: 40
    • http://www.corvettepalace.com
Uploading Files with PHP.
« Reply #2 on: January 12, 2004, 07:35:57 AM »
Quote from: artayd2
is the folder you are writing to , writeable?


Hi, the dir attributes are 775 should they be 777?


Thanks,

M

Offline Random Guest #1

  • Spacescooter Operator
  • *****
  • Posts: 43
Uploading Files with PHP.
« Reply #3 on: January 12, 2004, 08:12:05 AM »
Quote
$dir = "path/where/you/want/to/upload/files/"; //Change this to the correct dir


I would like to know how I should write this part of the code in my own code.

Should it be:

Code: [Select]
$dir = "http://www.mysite.com/subfolder/subfolder/";

if not, could you please tell me?

*Sorry for piggybacking. :p

Offline artayd2

  • Galactic Royalty
  • *****
  • Posts: 378
    • http://www.thundercats-hockey.com
Uploading Files with PHP.
« Reply #4 on: January 13, 2004, 05:41:58 AM »
Quote from: uripides
Quote from: artayd2
is the folder you are writing to , writeable?


Hi, the dir attributes are 775 should they be 777?


Thanks,

M


if 777 doesn't work, then it isnt a permission issue

Offline artayd2

  • Galactic Royalty
  • *****
  • Posts: 378
    • http://www.thundercats-hockey.com
Uploading Files with PHP.
« Reply #5 on: January 13, 2004, 05:42:42 AM »
Quote from: Random Guest #1
Quote
$dir = "path/where/you/want/to/upload/files/"; //Change this to the correct dir


I would like to know how I should write this part of the code in my own code.

Should it be:

Code: [Select]
$dir = "http://www.mysite.com/subfolder/subfolder/";

if not, could you please tell me?

*Sorry for piggybacking. :p


1st one

Offline Üripides

  • Spacescooter Operator
  • *****
  • Posts: 40
    • http://www.corvettepalace.com
Uploading Files with PHP.
« Reply #6 on: January 13, 2004, 07:05:23 AM »
Quote from: artayd2
Quote from: uripides
Quote from: artayd2
is the folder you are writing to , writeable?


Hi, the dir attributes are 775 should they be 777?


Thanks,

M


if 777 doesn't work, then it isnt a permission issue


i actually scratched the whole idea and went with a MySQL BLOB version that works a lot better for my purposes. i changed the folder CHMOD 777 and things work fine now.

Any one have any concerns about using BLOB Vs URL reference?



Thanks,

Matt

Offline stevepowell

  • Newbie
  • *
  • Posts: 4
Uploading Files with PHP.
« Reply #7 on: January 17, 2004, 07:48:21 PM »
I'm not that well versed with using chmod on lunarpage hosted sites.  Where would I go to change these permissions?  I'm trying to allow users to upload csv files to my site via a webpage - I am having problems with permission on move_uploaded_file() and mkdir().  Thanks! :?
Steve

Offline stevepowell

  • Newbie
  • *
  • Posts: 4
Uploading Files with PHP.
« Reply #8 on: January 17, 2004, 08:00:25 PM »
As a follow up, I've grabbed this cool example - works great - except for my permissions problem  :-?

http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=1198&lngWId=8
Steve

Offline Üripides

  • Spacescooter Operator
  • *****
  • Posts: 40
    • http://www.corvettepalace.com
Uploading Files with PHP.
« Reply #9 on: January 18, 2004, 07:17:45 AM »
Quote from: stevepowell
I'm not that well versed with using chmod on lunarpage hosted sites.  Where would I go to change these permissions?  I'm trying to allow users to upload csv files to my site via a webpage - I am having problems with permission on move_uploaded_file() and mkdir().  Thanks! :?



The easiest way to CHMOD iwould be to use an FTP client like Bulletproof or FlashFXP. search BulletProof FTP and DL the software, configure it for Lunarpages and then simply connet to the server. Next you can right click on the dir you want to change, select change properties, click that option, and it will show you the properties wich you can change, such as 777. It's really simple.

M