User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,574 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,597 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 842 | Replies: 8
Reply
Join Date: Oct 2007
Posts: 10
Reputation: aquilai is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
aquilai aquilai is offline Offline
Newbie Poster

Problems with file upload

  #1  
Oct 26th, 2007
Hi i'm trying to upload a picture to the server using a form and it all seems to be working fine the only problem is I can't seem to find the picture when its uploaded, the script runs fine and gives me no errors and then when I come to look in the folder where i think it should be, there is nothing there. I'm using a test environment on the mac and am using the inbuilt apache server on OSX but don't have any idea which is the root folder as far as the move_uploaded_file function is concerned:

$destination = "upload/";
move_uploaded_file($_FILES["pix"]["tmp_name"], $destination.$_FILES["pix"]["name"]);
echo "br />Moved to: " .$destination.$_FILES["pix"]["name"];

This is the offending code, now I would assume that the file would be in a folder called upload on the mac HD, anyone know where i'm going wrong!?

Cheers.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Chenoa, IL
Posts: 13
Reputation: bigattichouse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
bigattichouse's Avatar
bigattichouse bigattichouse is offline Offline
Newbie Poster

Re: Problems with file upload

  #2  
Oct 26th, 2007
use the actual path /path/to/your/html/upload
Need a simple, powerful knowledgebase? Bigattichouse Knowledge Base finds the solution while you're still typing the problem.
http://www.bigattichouse.com/knowledgebase.html
Reply With Quote  
Join Date: Oct 2007
Posts: 10
Reputation: aquilai is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
aquilai aquilai is offline Offline
Newbie Poster

Re: Problems with file upload

  #3  
Oct 26th, 2007
Sorry, realise I'm being amazingly thick here but just can't get my head around this, can someone explain this as if explaining to an idiot....which, come to think of it, is exactly you are doing!!!

Cheers
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: Problems with file upload

  #4  
Oct 26th, 2007
define full path
C:/websites/mysite/upload/
Do a favour, leave me alone
Reply With Quote  
Join Date: Oct 2007
Posts: 10
Reputation: aquilai is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
aquilai aquilai is offline Offline
Newbie Poster

Re: Problems with file upload

  #5  
Oct 27th, 2007
Right am thoroughly tearing my hair out on this one, thanks to you guys so far for your help, but I have a feeling there is something else happening apart from my inability to work out addressing properly, heres the full code,

$destination = '/upload/'.$_FILES["pix"]["name"];
echo $_FILES["pix"]["tmp_name"];
if(move_uploaded_file($_FILES['pix']['tmp_name'], $destination))
{
echo "br />Moved to: ".$destination;
}
else
{
echo "Not working fool".$destination;
}

I am using apache and php 5 on localhost, that is they are installed on my mac and i'm running the upload program through the webserver folder. I have created a folder on the mac HD called 'upload' but can't get the thing to work...any ideas.
Reply With Quote  
Join Date: Aug 2005
Location: somewhere in time
Posts: 81
Reputation: TopDogger is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: Problems with file upload

  #6  
Nov 1st, 2007
I think what people are trying to tell you is that you need to replace,

$destination = "upload/";

with

$destination = $_SERVER['DOCUMENT_ROOT']."/upload/";

That should fully specify your local path to the destimation directory.

You may also be running into problems trying to to this on a Mac. It might not work the same as on a Unix/Linux server.
Reply With Quote  
Join Date: Oct 2007
Posts: 10
Reputation: aquilai is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
aquilai aquilai is offline Offline
Newbie Poster

Re: Problems with file upload

  #7  
Nov 2nd, 2007
Thanks for all your help guys finally figured it out to be a problem with permissions I had them set to read rather than write on the folder i wanted the files moved to.

Once again cheers!!
Reply With Quote  
Join Date: Aug 2005
Location: somewhere in time
Posts: 81
Reputation: TopDogger is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: Problems with file upload

  #8  
Nov 3rd, 2007
It's usually a good idea to add the following to the top of any PHP script that you are troubleshooting.

error_reporting(E_ALL);

You would have seen the permissions issue right away.

But it is not a good idea to leave that statement active on a script on a production site.
Reply With Quote  
Join Date: Oct 2007
Posts: 10
Reputation: aquilai is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
aquilai aquilai is offline Offline
Newbie Poster

Re: Problems with file upload

  #9  
Nov 5th, 2007
Ahhh, now I see how easy that could have been!!

Cheers,
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC