Page 1 of 2

problem uploading a picture

Posted: Sat Oct 07, 2006 12:50 pm
by franknu
ok, I have the code that was actually working for me. for some reason it looks like it was saving it in the server not in the directory so , i made some changes and bhuh. it is not working anymore it is not saving anything
it says file uploaded but when i look in the database there is nothing not in the folder tha i assigned to it.. so here is the code

Code: Select all

<?php

 



 $uploaddir = realpath ("/home/townsfinder/biz.pictures");

if(!empty($_FILES['Picture1']))
 {
    var_dump($uploaddir);
    var_dump($_FILES);
	var_dump($_FILES['Picture1']['size']);
    var_dump($_FILES['Picture1']['error']);
    var_dump($_FILES['Picture1']['type']);
      

   if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $uploaddir .$_FILES['Picture1']['name']))
   
    {
       echo("File Uploaded");
   } 
   
   else 
   
   {
       echo ("file no uploaded!");
   }
}

  

?>

Code: Select all

bool(false) array(1) { ["Picture1"]=> array(5) { ["name"]=> string(11) "beer1_l.jpg" ["type"]=> string(11) "image/pjpeg" ["tmp_name"]=> string(42) "C:/Program Files/EasyPHP1-8\tmp\php4D0.tmp" ["error"]=> int(0) ["size"]=> int(3859) } } int(3859) int(0) string(11) "image/pjpeg" File Uploaded

Posted: Sat Oct 07, 2006 1:11 pm
by waradmin
Why is it doing C:/Program Files/EasyPHP1-8\tmp\php4D0.tmp (switching from / to \ randomly)

And out of pure confusion, why is your upload path /home/townsfinder/biz(DOT)pictures? It looks like your using a Unix path and a windows temp path, which I dont understand.

Posted: Sat Oct 07, 2006 2:06 pm
by franknu
Ok I change the path to a diffrent directory to ("hom/townsfinder/images/)

i am still getting an error message

Posted: Sat Oct 07, 2006 2:07 pm
by RobertGonzalez
You are mixing path types. Are you are on a windows system or *nix system?

Posted: Sat Oct 07, 2006 2:07 pm
by franknu
actually, it is not an error message, it is just not doing what it suppose to do..

Posted: Sat Oct 07, 2006 2:08 pm
by franknu
i am using windows

Posted: Sat Oct 07, 2006 2:11 pm
by RobertGonzalez
$uploaddir is returning a boolean false, which means that your realpath() call is failing. That means that eventhough the files is a clean file for uploading, the path that it is being sent to is not what you think it is as $uploaddir is not the path but a boolean false.

Two good resources to look at in this situation:
http://us2.php.net/move_uploaded_file
http://us3.php.net/realpath

Posted: Sat Oct 07, 2006 2:14 pm
by franknu
why is my is it failing it work before. do i have to get something else , that is the only one i found in the manual to upload a picture please help

Posted: Sat Oct 07, 2006 2:36 pm
by franknu
i am using $real_path and i am still not getting it. any other thing i should be doing for this

Posted: Sat Oct 07, 2006 2:38 pm
by waradmin
I would just GOOGLE php image upload script and you will find a ton of matches. Look at the code of those.

To point out the obvious you are using a Unix path and a Windows Path (which I believe is supposed to be done in the form of C://something//) so your upload script isnt being consistant.

Posted: Sat Oct 07, 2006 5:35 pm
by RobertGonzalez
franknu wrote:why is my is it failing it work before. do i have to get something else , that is the only one i found in the manual to upload a picture please help
I would guess it has something to do with you trying to real path a full Unix style path on a Windows system.

Posted: Sat Oct 07, 2006 9:41 pm
by franknu
i am confuse because the same code work before, i just went made some changes and then it stopped working

i think it has something to do with the path..

i am using windows maybe that is the probleme

here are the changes made

Code: Select all

<?php

 


 $uploaddir = realpath ("C:\Program Files\EasyPHP1-8\home\townsfinder\biz.pictures"); 
 $uploadfile = $uploaddir . basename($_FILES['Picture1']['name']);




if(!empty($_FILES['Picture1'])) 
 { 
    var_dump($uploaddir); 
    var_dump($_FILES); 
        var_dump($_FILES['Picture1']['size']); 
    var_dump($_FILES['Picture1']['error']); 
    var_dump($_FILES['Picture1']['type']); 
      }

   if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $uploaddir .$_FILES['Picture1']['name'])) 
    
    { 
       echo("File Uploaded"); 
   } 
    
   else 
    
   { 
       echo ("file no uploaded!"); 
	   print_r($_FILES);
   } 


  

?>
here is my display

Code: Select all

bool(false) array(1) { ["Picture1"]=> array(5) { ["name"]=> string(11) "beer1_l.jpg" ["type"]=> string(11) "image/pjpeg" ["tmp_name"]=> string(41) "C:/Program Files/EasyPHP1-8\tmp\php52.tmp" ["error"]=> int(0) ["size"]=> int(3859) } } int(3859) int(0) string(11) "image/pjpeg" File Uploaded

Posted: Sat Oct 07, 2006 9:47 pm
by RobertGonzalez
You are using realpath() incorrectly. What realpath() does is take a path like './' or 'dirname(__FILE__)' and turns it into a real, full path. Passing it a full path will make it choke because it is not expecting a full path.

Posted: Sat Oct 07, 2006 10:14 pm
by waradmin
I dont believe you can use the \ in the path as that is reserved for stuff like \n from what I understand. Your path should be C://___//___// If I recall correctly, you need to use double slashes in windows directories.

Posted: Sat Oct 07, 2006 10:27 pm
by RobertGonzalez
Do this and see what is returned:

Code: Select all

<?php
echo realpath('./');
?>