Jump to content

File upload problem.Help please


asherinho

Recommended Posts

Whats up guys? I am having a problem with the path to put the folder for uploaded files in the control panel.Below is the view of the directory tree,you can see the position of the uploads folder.Is that the correct place to put that folder? I have been getting this warnig

 

Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/uploads/ASHRY.gif) is not within the allowed path(s): (/home/mtibwa:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/mtibwa/public_html/upload.php on line 12

 

[/img]

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/137108-file-upload-problemhelp-please/
Share on other sites

FMaBiSmAd are you suggesting I should use "uploads/" as a path to where the file is uploaded? I tried it but still it doesn't work.Below is the code for the page which uploads the file

<?
$file_dir = "uploads/";
if($_FILES['fileupload']['size'] <= 81200){
  foreach($_FILES as $file_name => $file_array) {
      print "path: ".$file_array['tmp_name']."<br>\n";
      print "name: ".$file_array['name']."<br>\n";
      print "type: ".$file_array['type']."<br>\n";
      print "size: ".$file_array['size']."<br>\n";

     if (is_uploaded_file($file_array['tmp_name'])) {
          move_uploaded_file($file_array['tmp_name'],
             "$file_dir".$file_array['name']) or die ("Couldn't copy");
         print "file was uploaded!<br><br>";
     }
  }
}else{ print "large size!<br><br>";} 	 
?>  

 

 

Just uploads/ will be relative to the currently running script. If we assume you put the uploads folder where it is because you wanted it there, you must form a path to where it is at /home/mtibwa/uploads/. You could hard code this, but it is better to form it at runtime using $_SERVER['DOCUMENT_ROOT'] so that your script will continue to work no matter where it is at as long as the folder structure is maintained. This should work -

 

$file_dir = $_SERVER['DOCUMENT_ROOT'] . '/../uploads/';

I tried it taht way.

<?
$file_dir = $_SERVER['DOCUMENT_ROOT'] . '/../uploads/';
if($_FILES['fileupload']['size'] <= 81200){
  foreach($_FILES as $file_name => $file_array) {
      print "path: ".$file_array['tmp_name']."<br>\n";
      print "name: ".$file_array['name']."<br>\n";
      print "type: ".$file_array['type']."<br>\n";
      print "size: ".$file_array['size']."<br>\n";

     if (is_uploaded_file($file_array['tmp_name'])) {
          move_uploaded_file($file_array['tmp_name'],
             "$file_dir".$file_array['name']) or die ("Couldn't copy");
         print "file was uploaded!<br><br>";
     }
  }
}else{ print "large size!<br><br>";} 	 
?> 

 

It doesn't work yet.I am getting the following warnings

Warning: move_uploaded_file(/home/mtibwa/public_html/../uploads/ASHRY.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/mtibwa/public_html/upload.php on line 12

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpSoClj8' to '/home/mtibwa/public_html/../uploads/ASHRY.gif' in /home/mtibwa/public_html/upload.php on line 12

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.