File upload script help

Hi,

I have been trying to create a simple file upload script that will put a .pdf from my computer up onto my server. The problem I am having is, I do not totally understand the whole temp directory variable and I also dont understand how to move the file once it is uploaded temporarly. WHen I try to submit the file, I am getting the “failed to open stream” access denied error. If anyone can give me some help I would greatly appreciate it. THank you.

Ryry

Well first and foremost, you need to have the appropriate permissions. I think that is what is giving you the error message “Access Denied”.

That might not be the only problem, however. If you can provide us with some code that you have tried, perhaps we can look at it and go from there.

I copied the below out of one of my scripts. it also has some error checking for failure (abit more meaningful errors)

[php]

<? // Create variables that are easier to process and more meaningful. $FileSize = $_FILES[userfile][size]; $FileType = $_FILES[userfile][type]; $FileName = $_FILES[userfile][name]; $FileTemp = $_FILES[userfile][tmp_name]; $FileError = $_FILES[userfile][error]; switch ($FileError){ case "0": if (!copy($FileTemp, "/var/www/html/uploads/$FileName")) die("FAILURE in UPLOAD"); echo "SUCCESS
"; break; case "1": echo"

"; echo "ERROR: File Size is to large for PHP.INI"; echo "

"; break; case "2": echo"

"; echo "ERROR: File Size is to large for FORM"; echo "

"; break; case "3": echo"

"; echo"ERROR: File Only Partially Uploaded"; echo "

"; break; case "4": echo"

"; echo "ERROR: No FILE to Upload"; echo "

"; break; } ?>[/php]

Finally you might want to check out http://us4.php.net/features.file-upload. It does have more detail that can help you understand the file upload a bit better.

Good Luck

Paul, thank you for the help.

the problem I am having is figuring out what

"/var/www/html/uploads/"

should be replaced with to fit my needs. Also… how would I go about fixing my access permissions?

well the /var/www/html/uploads is the directory to copy the file too. (The ultimate destination).

I suppose at this point it’s important to note that I am on a Linux system. The location would be much different on a Windows system (perhaps something like c:inetrootuploads but don’t quote me on that as I don’t use IIS or PWS).

Either way, your webserver needs to have sufficient permissions to access both the temporary location of the file uploaded and the ultimate destination. If you manage your own server, then I can help you with the permissions. (it’s real easy), if you are using a hosting service, then it’s up to them to grant the permission . Again, this is platform dependant.

Finally, if you are using a third party hosting, they might have restrictions on your uploading (via http).

Paul

http://www.acecoolco.com/tutorials.php

I have an upload file tutorial available.

Your sooo cool 8) [size=99px]Sorry I couldn’r resist [/size] :D

Paul,

Thanks for the replys. I am using a hosting service for my site and I am using ipowerweb.com. Everything has been fine except for this file upload problem. I guess I will just have to settle for a different method to complete my project.

Also… speaking about servers…my site is going to demand a lot of online storage space. Right now, ipowerweb is giving me only 800 mb of space, is building your own server a difficult task, and do you think that would be the right way for me to go? Anyone else have any opinions? Well, thank you for your help everyone and hope to see some replys.

Thanks in advance.

P.S. Is there a way to find out for sure if my hosting service does not support file uploads via http?

Building the server in itself is not (necessarily) a difficult task. Maintaining it is probably the bigger problem.

Financially you will have to deal with :

  • equipment costs
  • Network connection (Typically need a DSL speed or higher)
  • Static IP Address (or Dynamic DNS Hoster)
  • DNS / Registrar fees.

As you can see costs can be an issue. Then you need to ensure that you keep your system secure. Hackers will be trying to get in all the time (Check Logs Frequently), then you need to keep up with the latest software updates.

I personally don’t mind doing much of this, but that is me. You need to weigh the cost vs benefit for yourself (Not just dollars, but time/effort as well).

Sponsor our Newsletter | Privacy Policy | Terms of Service