php upload form - windows doesn't let me get the file??

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

Post Reply
The Booboo
Forum Newbie
Posts: 1
Joined: Mon Dec 05, 2005 5:16 pm

php upload form - windows doesn't let me get the file??

Post by The Booboo »

I'm using a php script to upload a file from a windows pc to the mysql database on my server. The script works fine if I specify the file's location as within the directory the script's running in, but it snags up if I'm uploading from Windows. I'm assuming this is because the windows security won't let my script get at the file? How do I get around this? If I open up this script to other users, I don't want them to have to fiddle with windows security or file permissions in order to use it. OR am I barking up the wrong tree, in which case can anyone see what I'm doing wrong?

Here's the basic script I'm using just to test the functionality:

Code: Select all

<?php

include ("connect.php");  // connects to the database

$filename = "c:\\ae-mess.JPG";  // location of test file on my home pc.

$handle = fopen($filename, "rb");
if (!($handle)) {
echo "handle failed!";
}
$contents = fread($handle, filesize($filename));
if (!($contents)){

echo "contents failed!";
}
fclose($handle);

mysql_query("INSERT INTO upltest VALUES ('', '$contents')");

echo "The script has run";
echo $contents;   // I know this will output giberish as the content type hasn't been set, but it's just to make sure that there's something there.

// Now run the same code again, but with a file stored on the server in the same folder:

$filename = "ae-mess.JPG";

$handle = fopen($filename, "rb");
if (!($handle)) {
echo "handle failed!";
}
$contents = fread($handle, filesize($filename));
if (!($contents)){

echo "contents failed!";
}
fclose($handle);

mysql_query("INSERT INTO upltest VALUES ('', '$contents')");

echo "The script has run";
echo $contents;     // this second bit runs ok.
?>
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

you are dealing with a file that is already on the same server as the script in your code, if you want to upload a file from a client machine via an html form then you need to look into the file handling functions for uploaded files such as

Code: Select all

move_uploaded_file()
Post Reply