473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

File Upload Error (Apache & PHP)

chunk1978
224 100+
hi there...

i have the following codes (HTML and PHP) on my Apache Localhost:

HTML: titled "Form.html"
Expand|Select|Wrap|Line Numbers
  1. <form enctype="multipart/form-data" action="uploader.php" method="POST">
  2. <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  3. Choose a file to upload: <input name="uploadedfile" type="file" /><br />
  4. <input type="submit" value="Upload File" />
  5. </form>
  6.  
PHP: titled "uploader.php"
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $target_path = "uploads/";
  3.  
  4. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
  5.  
  6. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  7.     echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
  8.     " has been uploaded";
  9. } else{
  10.     echo "There was an error uploading the file, please try again!";
  11. }
  12. ?>
  13.  
i've also created a folder called "uploads" in the same directory as the .html and .php files.

the problem i'm having is that i always get the message:

"There was an error uploading the file, please try again!"

i don't know what i'm doing wrong... this is the most basic php upload script... does Apache not allow files to be written to the localhost folders? am i suppose to change anything in my php.ini file? the file i attempted to upload is really small, and well below the php.ini's max file/memory size limits...

anyone?
Apr 25 '07 #1
5 13871
Banfa
9,065 Expert Mod 8TB
Hve you changed the permissions on the directory uploads to allow files to be written to it. If you haven't the move can fail because the default user does not have permissions to write in that directory.

You should be able to check and alter the directory permissions via your ftp client, set them to 777 (assuming that you have a Linux server).
Apr 25 '07 #2
chunk1978
224 100+
Hve you changed the permissions on the directory uploads to allow files to be written to it. If you haven't the move can fail because the default user does not have permissions to write in that directory.

You should be able to check and alter the directory permissions via your ftp client, set them to 777 (assuming that you have a Linux server).
hi banfa... thanks for replying... i included the $_Files['error'] code into the script and it gave me a "0" error, which means that everything was fine and there is no error... but it says "0 - There was an error uploading the file, please try again!"... so there's defiantly something crazy going on...

i don't understand how i can change directory permissions on my localhost (my mac's "sites" folder) using FTP... i don't use FTP to create folders or move files... i just drag and drop, or create a file or folder within the "sites" folder in Mac OS X. but maybe there's still a way to have permissions with a localhost running Apache?
Apr 25 '07 #3
Banfa
9,065 Expert Mod 8TB
I have no idea how to change directory permissions on a Mac running OS X, although I do believe that OS X is based on Linux and therefore it is possible that the same permissions structure is in place.

You drag and drop to create files and folders but you are able to do it because you as a user have permissions to do it. The default user used by Apache when running may not have these permissions.

Not your if statement that causes the message "0 - There was an error uploading the file, please try again!" to be output does not test the upload, it tests the ability to copy the file once it is uploaded (the error message is misleading).

The move_uploaded_file documentation suggests that as long as the first parameter is a valid file name to a file uploaded to php via a post then if the function fails it will output a warning message. Do you have warnings switched on?

Finally you say you created a uploads directory, are you sure the capitalisation is correct?
Apr 25 '07 #4
chunk1978
224 100+
I have no idea how to change directory permissions on a Mac running OS X, although I do believe that OS X is based on Linux and therefore it is possible that the same permissions structure is in place.

You drag and drop to create files and folders but you are able to do it because you as a user have permissions to do it. The default user used by Apache when running may not have these permissions.

Not your if statement that causes the message "0 - There was an error uploading the file, please try again!" to be output does not test the upload, it tests the ability to copy the file once it is uploaded (the error message is misleading).

The move_uploaded_file documentation suggests that as long as the first parameter is a valid file name to a file uploaded to php via a post then if the function fails it will output a warning message. Do you have warnings switched on?

Finally you say you created a uploads directory, are you sure the capitalisation is correct?
hi again... about the naming of the folder, i've tried several folders and the names of the folder is the same as what's written in the script.

Mac OS X is unix based, so it's for sure the same procedure of granting permissions... but i just don't have any idea how to grant the 777 permission... am i suppose to enter some commands in the terminal window?
Apr 25 '07 #5
to change the permissions in OSX open terminal and type chmod 777 followed by the path to the directory or files you are changing.

eg: chmod 777 sites/test1

if you then type "cd" (without the "") followed by the directory containing the files you are modifying (eg: cd sites) then type "ls -al" you will be given a list of the files in that diectory with the permissions listed on the left hand side. 777 will grant all access (read, write, execute) to the owner, groups, and other users. To grant the reqired permissions that you want i sugest that you type "man chmod" which will open a manual file that explains the comand chmod further. this also has a description of the numerical combinations needed to get the desired result.

i hope this helps! :P
May 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
1
by: pmz | last post by:
Dear Group, I'm currently developing a simple Windows application in C#, which is supposed to upload images - through 'WebClient' - into remote (FreeBSD/Apache/PHP) server. What is...
8
by: mpar612 | last post by:
Hello, I am a newbie to PHP, MySQL. I am trying to create a basic file upload form. I want to get that working and then I want to integrate that into a form that will rename the file and save...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
Atli
by: Atli | last post by:
Hi. I'm trying to use php code I wrote last year when I was using Apache, so I'm pretty sure the code works. Its a simple code to upload an image and create a thumb of the image in another...
1
by: ctiggerf | last post by:
I am having some troubles with file uploads on my server and was hoping you guys could help out. PHP is returning with the error UPLOAD_ERR_INI_SIZE for all files over approx. 4Kb. I have set...
3
chunk1978
by: chunk1978 | last post by:
hi there... i have the following codes (HTML and PHP) on my Apache Localhost: HTML: titled "Form.html" <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input...
6
by: Milan Krejci | last post by:
while(list($key,$value) = each($_FILES)) { if(!empty($value)){ $filename = $value; $add = "upimg/$filename"; echo $_FILES; $error=copy($_FILES, $add); if (!$error)...
16
by: Lawrence Krubner | last post by:
To guard against our users possibly uploading huge files, I've got this in my php.ini file: ; Maximum size of POST data that PHP will accept. post_max_size = 10M On a server running Ubuntu...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.