Uploading Photo To Server To Use As Profile Picture.
Solution 1:
NOTE: This is a Suggestive answer.
Remove or comment out this line: $target = "/var/www/profile";
and place the code I posted below, underneath your mail()
function,
or above $message = "To activate your account...
and give that a try/test.
PATH NOTE: in regards to $upload_path = './uploads/';
in my code,
this is assuming that you are running your script from the root
of your server.
You could try $upload_path = '/var/www/profile/uploads/';
but you will need to keep the trailing slash.
You will also need to delete/comment out $target = $target . basename($_FILES['photo']['name']);
,
or better yet, use my code in that space instead. You will have to test in which spot it will be work best.
Here is my (tested) code:
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.$max_filesize = 9999999999; // Maximum filesize in BYTES - SET IN to a low number for small files$upload_path = './uploads/'; // The place the files will be uploaded to (currently a 'files' directory).$filename = $_FILES['photo']['name']; // Get the name of the file (including file extension).$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.// Check if the filetype is allowed, if not DIE and inform the user.if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.if(filesize($_FILES['photo']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.if(move_uploaded_file($_FILES['photo']['tmp_name'],$upload_path . $filename))
echo'Your file upload was successful'; // It worked.elseecho'There was an error during the file upload. Please try again.'; // It failed// rest of your code to be placed below
Solution 2:
This is not a complete fix but I notice a couple of things
As others have suggested you are not moving the picture to a location you can access. Also:
while($row = mysql_fetch_array($result)) { header("Content-type: image/jpeg"); echo mysql_result($result, 0); }
Seems to be using the header() term after you have sent output to the browser. I do notice that you are using ob_start to buffer your output but don't think this will prevent unexpected results.
In the same block of code you seem to be returning the entire row from the mysql result, not just the .jpg data. I suspect that this is the more likely issue since
$result = mysql_query("SELECT * FROM animator.account WHERE idaccount=" . $_SESSION['idaccount'] . ";");
Is returning an array with all of the fields from the database. A quick test of the latter theory would be to replace your query with
$result = mysql_query("SELECT picture FROM animator.account WHERE idaccount=" . $_SESSION['idaccount'] . ";");
Very interested to hear your results.
Post a Comment for "Uploading Photo To Server To Use As Profile Picture."