Forum Moderators: coopster
i am a neo phite here so bare with me...
i created an html form and php script that allows me to upload images to my server... seems to be working accept when the file gets to the server, the permissions keep getting changed so that the image is an "un authorized url" meaning even a simple <img src=""> tag can not be used to display the image.. i checked the chmod of the folder and the php script and they are all set to read, write, and execute for all three groups..(ie. user, owner, group all have full read, write, and execute.. well that is until the image is uploaded through my php script..)
anyway.. here is the php script i am using.. idealy i want the script to take the user selected file.. upload it to the same directory as the php script and name it bio1.jpg...
<?php
// Where the file is going to be placed
$target_path = "uploads/";
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
$target_path = "bio1.jpg";
//$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded and saved as the image for bio 1";
} else{
echo "There was an error uploading the file, please make sure that the file is a jpg, 384 pixels wide and 286 pixels high, then try again!";
}
?>
<img src="bio1.jpg">
As you get more into PHP, learn from others' code so you do not have to waste time re-inventing a wheel each time.
the weird thing is after i check all this and they are all 777.. i goto the html form... upload a file and bang. its there but the chmod to the html changes to 666 chmod the thimage changes to 600 and the only file that remains 777 is the php script!
please help!
can you use chmod [php.net] on the image right after you upload it? the script should be the owner and can set the proper permissions right at that time.
its not working
here is how my script looks currently
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
$target_path = "bio1.jpg";
chmod ("bio1.jpg", 0777);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded and saved as the image for bio 1";
} else{
echo "There was an error uploading the file, please make sure that the file is a jpg, 384 pixels wide and 286 pixels high, then try again!";
}
?>
<img src="bio1.jpg">
unfortunately its still changing the chmod of the bio1.jpg to 600..
what am i doing wrong
?
<?php
$mode ="777";
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
$target_path = "bio1.jpg";
echo $mode;
chmod("bio1.jpg", $mode);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded and saved as the image for bio 1";
} else{
echo "There was an error uploading the file, please make sure that the file is a jpg, 384 pixels wide and 286 pixels high, then try again!";
}
?>
<img src="bio1.jpg">
this is a new file and sometimes the permissions get changed in that new location
so you need to chmod the final destination because that is the file you are trying to call with the image tag
your error is permissions on that file/dir/user whatever
that make sense?