Hi,
I am fairly new to PHP. I have mastered forms, but now need to add a file upload facility to one. I have searched for coding etc, and tried to apply it to my forms.
My only problem as far as I can see, is in the following line, where I tell the form where to upload the file to -
copy("$superdat", "http://www.mywebsite.com/home/mycontrol ... p/incoming /uploading/$superdat_name") or
die("Couldn't copy file.");
I can't seem to get the path/address correct, as I keep getting this message when I upload my forms and go in as a user to test them. When I click submit, this is the error that I get -
Warning: Unable to create 'http://www.mywebsite.com/home/mycontrol ... p/incoming /uploading/emaillogosmall.gif': No such file or directory in /home/mycontrolpanelloginname/public_html/upload.php on line 21
Couldn't copy file.
Of course, I have changed some of the names to put this on here. But, I think my main problem, is that in my php coding, where I have the line that tells the form where to upload the file to on my web site server, I am not putting the correct address.
The file 'uploading' has user write permissions, so that part is fine. I just can't grasp the correct way to write the actual path/address to place the file. I have tried '/public_ftp/incoming/uploading/' , I have tried 'http://www.mywebsite.com/public_ftp/incoming/uploading/' , I have tried '/home/mycontroplanelusername/public_ftp/incoming/uploading/' , and I have also tried placing the 'uploading' file just straight on my hositing directory and also in my 'public_html' file. Nothing seems to work. I am on a shared Web Hosting service, does this make a difference?
How do I correctly write the path/address on a shared Unix server?
error when using file upload form
Moderator: General Moderators
Change path to this and see what happens
Code: Select all
$DOCUMENT_ROOT/home/mycontroplanelusername/public_ftp/incoming/uploading/-
bionicdonkey
- Forum Contributor
- Posts: 132
- Joined: Fri Jan 31, 2003 2:28 am
- Location: Sydney, Australia
- Contact:
this is a script i wrote for uploading images:
Code: Select all
<?
if(isset($invoke) == 'Upload Image') {
$username = $authdata['username'];
$filename = $HTTP_POST_FILES['userfile']['name'];
if(substr($HTTP_POST_FILES['userfile']['type'], 0, 5) != 'image') { // Check if image
die("Upload Aborted! Uploaded file not an image.");
}
if(file_exists("../images/".$filename)) { // If file already exists
for($i = 1; $i <= 1000; $i++) {
$tmp = explode(".", $filename);
$file = $tmp[0];
$ext = $tmp[1];
if(!file_exists("../images/".$file.$i.$ext)) {
$filename = $file.$i.".".$ext; // rename new file
break;
}
}
}
mysql_query("INSERT INTO images VALUES ('$filename', '$imagename', '$username')");
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], "../images/". $filename); // Move to new location
} else {
echo "Possible file upload attack. Filename: " . $HTTP_POST_FILES['userfile']['name'];
}
echo "Data submited";
}
?>Decoy1 Thank you so very very much! I am a very happy girl!
Your method worked! I only needed to make one change to it, that was - I cut out the middle stuff and just put - $DOCUMENT_ROOT/uploading/
and it worked at last. It is good that I had to cut out the middle stuff including my controlpanelloginname as I would hate for somebody to hack in and find out what my username is.
Bionicdonkey, I still would like to find out whether your code involves sessions and users with usernames, and if so whether I can cut that line out, as it is always great to know of other codes that work, so that they can be combined to suit my changing needs.
Thank you both very much, I am so releived to find the answer at last.
Your method worked! I only needed to make one change to it, that was - I cut out the middle stuff and just put - $DOCUMENT_ROOT/uploading/
and it worked at last. It is good that I had to cut out the middle stuff including my controlpanelloginname as I would hate for somebody to hack in and find out what my username is.
Bionicdonkey, I still would like to find out whether your code involves sessions and users with usernames, and if so whether I can cut that line out, as it is always great to know of other codes that work, so that they can be combined to suit my changing needs.
Thank you both very much, I am so releived to find the answer at last.
-
bionicdonkey
- Forum Contributor
- Posts: 132
- Joined: Fri Jan 31, 2003 2:28 am
- Location: Sydney, Australia
- Contact: