php upload form - windows doesn't let me get the file??
Posted: Mon Dec 05, 2005 5:25 pm
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:
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.
?>