Hey guys I'm following these tutorials on php image upload where user signs up creates an album and can upload images into a specific album.
file structure would be folder will be created in uploads and uploads/thumbs with user's id and all images from that user will be stored in there.
problem is my code works perfect on local server but on live server details get set to the database fine but no upload happens and no error returns...
file permissions are 744 755 in code and on the actual folders on server. Is there anything that comes to mind that I could try?
function upload_image($image_temp, $image_ext, $album_id) {
$album_id = (int)$album_id;
mysql_query("INSERT INTO `images` VALUES ('', '".$_SESSION['user_id']."', '$album_id', UNIX_TIMESTAMP(), '$image_ext')");
$image_id = mysql_insert_id();
$image_file = $image_id.'.'.$image_ext;
move_uploaded_file($image_temp, 'uploads/'.$album_id.'/'.$image_file);
move_uploaded_file($_FILES["file"]["tmp_name"],"images/". $_FILES["file"]["name"]);
Thumbnail('uploads/'.$album_id.'/', $image_file, 'uploads/thumbs/'.$album_id.'/');
}
Related
I'm making a simple PHP application which can upload an image to server.
I did it in my localhost, everything works well, but when I did it in real server. I mean web.com, it didn't work.
Here is my PHP script :
<?php
require "init.php";
$encoded_string=$_POST["encoded_string"];
$userfname=$_POST["userNameOf"];
$decoded_string=base64_decode($encoded_string);
$string= str_replace(' ','', $userfname);
$path="http://mybookshare.com/photos/" .$string. ".jpg";
file_put_contents($path,$decoded_string);
$query = "UPDATE user SET ProfPicture='$encoded_string' WHERE UserFN='$userfname' AND ProfPicture IS NULL";
$result = mysqli_query($conn, $query);
if($result) {
echo "success";
} else {
echo "failed";
}
mysqli_close($conn);
?>
The script is located in htdocs/app, and the upload file destination of the picture is at htdocs/photos
Any help please?
Problem :
You don't have photos directory as in your script directory.
Solution :
Try to move your photos directory from your sub directory to your script main directory where your PHP file is present and then you will have no errors.As you can see that the script says that your directory is not present so that's why it's failing to do the rest of process.
Heads Up :
I already said the same thing in my first comment but seems like you didn't give much attention to it.as you were mentioning the photos directory as to be present in your php script directory for your php to work it out with that and then you were not having the photos directory there so that's what was causing the error.!
i am using php code for creating folder at run time where i am storing some images.
when i try to accecss these image it does not show images asa well as folder name using appropriate URL.
but when i logedin using cpanel it shows folder name.
Here is my code
$dir="1buyerseller";
$desired_dir=$email;
$filename= $dir.'/'.$email.'/'.$file_name;
//echo $filename;
$query="INSERT into buysellsetailads (id,ads,cid) VALUES('seller','$filename','$cid'); ";
if(empty($errors)==true){
if(is_dir($dir.'/'.$desired_dir)==false){
mkdir("$dir/$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$dir/$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"$dir/$desired_dir/".$file_name);
}else{ // rename the file if another one exist
$new_dir="$dir/$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
mysql_query($query);
}
Using this code i am creating folder and uploding image into this folder.
whnen i try like this
http://www.xpokerala.com/admin/1square/
Here some folder are showing which created hardcoded but dyanamic created not showing
Why i dondt no.
How can i resolve this issue
Thanks
$query="INSERT into buysellsetailads (id,ads,cid) VALUES('seller','$filename','$cid'); ";
should this be buysellretailads?
How do I get files to upload online? This works well locally, but I cannot get the file to upload online to my cpanel server. I cannot see the path in my database, and the file is not uploaded into the researches file.
Here is my code:
if($name=="") echo "Enter the Research Title.<br/>";
else{
$uploadfile = basename($_FILES['imageupload']['name']);
$fileTmpLoc = $_FILES["imageupload"]["tmp_name"];
$moveResult = move_uploaded_file($fileTmpLoc, "researches/".$uploadfile);
$path = $uploadfile.".pdf";
$sql = mysql_query("INSERT INTO researches (name, link, date) VALUES ('$name', '$path', '$date')");
echo "Research Uploaded successfully.<br/>";
echo "<meta http-equiv='refresh' content='2, url=researches.php' >";
}
}
?>
I hope "researches" is a DB in which you want to INSERT files every time you needed. If that is not allowing to upload (INSERT) files to the DB, Make sure that the DB user is having necessary privileges to perform the action.
Anyway I don't see anything regarding DB user. You simply give all privileges to the corresponding DB user for the DB researches.
I am writing a PHP script that enables a user to upload a picture and then displays it on their page. Everything works fine up until the part where they need to display it. I run the form and submit it and the picture shows up in the directory in my FTP. I can download that file from the FTP and view it on my computer. I can visit the FTP url of that image, login and see it fine.
When I go to the HTTP version of the exact same URL, I get a 404 error. I have checked the permissions on the folder and it's ok to read and write for a user. I even checked the permissions on the file itself after it's uploaded and it's fine. Here's my PHP code when uploading the file:
<?php
include('connect.php');
$user_id = $_SESSION['user_id'];
if($_POST['submit']){
//GET FILE ATTRIBUTES
$name = $_FILES['myfile']['name'];
$size = $_FILES['myfile']['size'];
$tmp_name = $_FILES['myfile']['tmp_name'];
if ($name){
//start upload process
$location = "pics/$name";
move_uploaded_file($tmp_name,$location);
$sql = "UPDATE tbl_name SET imagelocation='$location' WHERE user_id='$user_id'";
$query = $mysqli->query($sql);
header('location:profile.php');
}
else{
die("Please select a file! <a href='profile.php'>GO BACK</a>");
}
}
?>
Any idea what this could be? I haven't seen this problem before.
i think folder permission may not be right when you created the folder with mkdir(). hope setting right permission will solve the problem.
It works now. I deleted the folder and recreated the folder with the same name. The folder was initially created through mkdir in PHP so I'm sure that had something to do with it. If anybody has any insight into why the folder wouldn't work with mkdir, feel free to post here. Thanks!
I recently moved a website that was written for a LAMP environment to Windows Server 2008. I've managed to get just about everything working now, but I've got one last problem that I can't seem to solve.
I am letting the admin user upload a photo that will get resized to a large file and small file by the PHP script. Both files are getting uploaded perfectly but the large file won't display and will result in a "500 internal server error" when viewed?
I can log onto the server and open both the small and large file, but only the small file is showing on the website? I've copied the PHP script below but the permissions on both files seem to be the same.
I'm using PHP, IIS7 and Windows Server 2008. Hope someone can help,
Steven.
// only process if the first image has been found
if(isset($image_file)) {
// get photo attributes
$image_filename = $image_file['name'];
$image_temp = $image_file['tmp_name'];
$image_ext = substr($image_filename,strpos($image_filename,'.'),strlen($image_filename)-1);
// validate photo attributes
if(strtolower($image_ext) == '.jpg' && filesize($image_temp) <= 4194304) {
// create custom timestamp
$image_timestamp = date('dmYHis');
// clean up filename
$image_filename = trim(str_replace('\'','',$image_filename));
$image_filename = str_replace('\\','',$image_filename);
$image_filename = str_replace('&','',$image_filename);
$image_filename = str_replace(' ','-',$image_filename);
// set file names
$image_large_file = strtolower($image_timestamp . '-large-1-' . $image_filename);
$image_small_file = strtolower($image_timestamp . '-thumb-1-' . $image_filename);
// image url source
$image_source = $_SERVER['DOCUMENT_ROOT'] . '/images/';
// upload image file
if(move_uploaded_file($image_temp,$image_source . $image_large_file)) {
// resize, save & destroy LARGE image
list($image_width,$image_height) = getimagesize($image_source . $image_large_file);
$image_container = imagecreatetruecolor(420,315);
$image_temp = imagecreatefromjpeg($image_source . $image_large_file);
imagecopyresampled($image_container,$image_temp,0,0,0,0,420,315,$image_width,$image_height);
imagejpeg($image_container,$image_source . $image_large_file,75);
imagedestroy($image_container);
// resize, save & destroy SMALL image
list($image_width,$image_height) = getimagesize($image_source . $image_large_file);
$image_container = imagecreatetruecolor(90,68);
$image_temp = imagecreatefromjpeg($image_source . $image_large_file);
imagecopyresampled($image_container,$image_temp,0,0,0,0,90,68,$image_width,$image_height);
imagejpeg($image_container,$image_source . $image_small_file,100);
imagedestroy($image_container);
}
else
$status = '<h3 class="red">Sorry, but there was a problem uploading one of the images to the server</h3>';
}
else
$status = '<h3 class="red">Please check that all the image size\'s are less than 4MB and they\'re all in JPG format</h3>';
}
I know this questions was asked 4 years ago, but I just ran into this same problem, and thought I'd leave an answer for anyone who may come here later.
I found an answer here, but the basic premise is to modify the permissions of the temp folder that PHP initially uploads into. Allowing the IUSR account read access to the temp folder will allow them to view the file when it hits its final destination. Supposedly IIS7 will grant the permissions from the temp folder to the temporary upload file, which, when moved to your website directory, will keep those temp folder permissions.
Security-wise, you are allowing read access to your temp folder; so if you have sensitive information that ends up there at any point, you may have to find another solution.
A little more information can be found here
I got stuck into the same problem and i think this will help somebody
Right-Click uploads directory / folder and select ‘Properties’
Go to ‘Security’ tab
Click Edit
Select ‘IUSR’ under group or user names
Select ‘Read & Execute’ under permissions for IUSR
Click ‘Apply’ and ‘Ok’
Found this on http://wingedpost.org/2016/07/preventing-500-internal-server-error-uploaded-files-iis-php-sites/