problem uploading a picture

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

problem uploading a picture

Post 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
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post 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.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

Ok I change the path to a diffrent directory to ("hom/townsfinder/images/)

i am still getting an error message
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You are mixing path types. Are you are on a windows system or *nix system?
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

actually, it is not an error message, it is just not doing what it suppose to do..
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

i am using windows
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post 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
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

i am using $real_path and i am still not getting it. any other thing i should be doing for this
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do this and see what is returned:

Code: Select all

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