Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Can somebody help make me a PHP uploader?

Can somebody help make me a PHP uploader?
Thread Tools
lothar56
Grizzled Veteran
Join Date: Jan 2001
Location: Iowa State Univesity
Status: Offline
Reply With Quote
Mar 25, 2006, 03:17 PM
 
I've looked at a ton of tutorial and stuff but I can't seem to get it to work. All I want to do is have a web page where I can browse, choose a file, then upload it to my server. It's running OS 10.4.5 with Apache 1.3 and PHP 5.1.2. The server's address is http://gossamerthree.student.iastate.edu, and the file path for uploads would be /Library/WebServer/Documents/Uploads. This is just a little server of my own to put pictures and stuff on, security is not important, but for what I'm doing with it it would be nice to have a little password or something. Can any of you gurus help me?
iBook G4-1.33/768 || B&W G3-450/640 || Beige G3-G4 450/352 || Beige G3-400/256 in Classic case || Beige G3-300/256 || PB 5300cs Pictureframe 100/24
     
bluedog
Mac Elite
Join Date: Aug 2000
Location: Minneapolis, MN
Status: Offline
Reply With Quote
Mar 27, 2006, 12:32 AM
 
Why does it have to be a web upload? For what you want, just enable Ftp? I can't imagine a scenario where you have a web access but not FTP unless the ftp traffic is blocked.

FTP would be dead simple, gives you basic authentication and just works.

For PHP there are some scripts around. I'll look at the code I have for uploads. Its not like you want the uploaded file to then be available for viewing on your web browser, right?
     
lothar56  (op)
Grizzled Veteran
Join Date: Jan 2001
Location: Iowa State Univesity
Status: Offline
Reply With Quote
Mar 27, 2006, 01:46 PM
 
I had considered FTP, but discarded it initially because I'd like for totally non-computer literate people to use this, but really it's not hard to figure out, so I might go with that anyway. What's the best FTP server software for OS 9?
The main point of this project is to allow people to remotely change the desktop picture, so if I use an app that automatically changes the picture at a set interval and set pictures to go into a specific folder that the program reads out of, it should work fine.
iBook G4-1.33/768 || B&W G3-450/640 || Beige G3-G4 450/352 || Beige G3-400/256 in Classic case || Beige G3-300/256 || PB 5300cs Pictureframe 100/24
     
SirCastor
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status: Offline
Reply With Quote
Mar 27, 2006, 04:22 PM
 
What code have you tried to get to function? And what errors are you receiving when you're working on it?
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
     
lothar56  (op)
Grizzled Veteran
Join Date: Jan 2001
Location: Iowa State Univesity
Status: Offline
Reply With Quote
Mar 28, 2006, 02:04 AM
 
I can't find the tutorials I was using earlier. None of them really had the code written out though, just randoms bits through, which made it hard to copy and paste well.
iBook G4-1.33/768 || B&W G3-450/640 || Beige G3-G4 450/352 || Beige G3-400/256 in Classic case || Beige G3-300/256 || PB 5300cs Pictureframe 100/24
     
SirCastor
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status: Offline
Reply With Quote
Mar 28, 2006, 02:52 AM
 
This one looks pretty good, pretty whole:
http://www.tizag.com/phpT/fileupload.php

read through all that, and put forth any questions you have.
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
     
lothar56  (op)
Grizzled Veteran
Join Date: Jan 2001
Location: Iowa State Univesity
Status: Offline
Reply With Quote
Mar 30, 2006, 08:29 PM
 
Originally Posted by SirCastor
This one looks pretty good, pretty whole:
http://www.tizag.com/phpT/fileupload.php

read through all that, and put forth any questions you have.
Okay, here is my severly flawed code:
uploader.html:
Code:
<HTML> <HEAD> <TITLE>uploader.html</TITLE> </HEAD> <BODY> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> </BODY> </HTML>

and uploader.php
Code:
<HTML> <HEAD> <TITLE>uploader.php</TITLE> </HEAD> <BODY> <?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); // This is how we will get the temporary file... $_FILES['uploadedfile']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {     echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{     echo "There was an error uploading the file, please try again!"; } ?> </BODY> </HTML>
when i choose a picture and hit upload, safari takes me to a blank page called uploader.php and nothing else happens. I know there are horrid errors there, let me know what they are!
iBook G4-1.33/768 || B&W G3-450/640 || Beige G3-G4 450/352 || Beige G3-400/256 in Classic case || Beige G3-300/256 || PB 5300cs Pictureframe 100/24
     
SirCastor
Professional Poster
Join Date: Jan 2001
Location: Salt Lake City, UT USA
Status: Offline
Reply With Quote
Mar 31, 2006, 05:22 AM
 
Your code worked flawlessly for me. Here's two things:

1) Make sure that the uploads directory exists, and that it has permissions set properly to be written to by the web server (in the case of OS X, it's user 'www')

2) If you're still running into difficulties, turn on error displaying in PHP on the server. It's immensly useful when you're trying to figure out what's going on.

I'd be willing to bet it's a permissions issue over anything else.
If you have more questions, ask away.
2008 iMac 3.06 Ghz, 2GB Memory, GeForce 8800, 500GB HD, SuperDrive
8gb iPhone on Tmobile
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:50 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,