Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:55:17+00:00 2026-06-14T10:55:17+00:00

I am using the POST method to upload a photo in my upload_photo.php file

  • 0

I am using the POST method to upload a photo in my upload_photo.php file which uses uploader.php to process the image. Uploader.php will resize the image and overwrite the old one. It works fine locally, but not on the server.

move_uploaded_file returns false, but $_FILES['uploadedfile']['error'] == 0 which does not make since to me.

I have posted the entire uploader.php and a snippet from upload_photo.php which shows the form tag.

<?php
//This is uploader.php
session_start();
include ('dbconfig.php');
include('SimpleImage.php');

mysql_connect(HOST, USERNAME, PASSWORD);
$conn = mysql_select_db(DB_NAME);

$target_path = "uploads/";

$target_path = $target_path . renameImage();

$_SESSION['client_photo'] = $target_path;

$query = "UPDATE client ";
$query .= "SET personal_photo = ('$target_path') ";
$query .= "WHERE client_id = ".$_SESSION['clientID'];
$results = mysql_query($query) or die('Error msg: '.mysql_error().'<br/>
        sql: '.query.'<br/>');

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  $msg = "The file ".  $_SESSION['client_photo']. 
  " has been uploaded";
  chmod($target_path, "0666");
  $work = new ImgResizer($target_path); 
  $work -> resize(600, $target_path); 
} else{
  $msg = "There was an error uploading the file, please try again!";
  $msg .= $_FILES['uploadedfile']['error'];
}
header("Location: upload_photo.php?msg=$msg");

function renameImage(){ 
  mysql_connect(HOST, USERNAME, PASSWORD);
  $conn = mysql_select_db(DB_NAME);

  $sql = "SELECT first_name, last_name, client_id
          FROM client
          WHERE client_id = ".$_SESSION['clientID'];
  $res = mysql_query($sql) or die('Error msg: '.mysql_error().'<br/>
                sql: '.$sql.'<br/>');
  if($row = mysql_fetch_array($res, MYSQLI_ASSOC)){
      $_SESSION['successphoto'] = 1;
      return $row{first_name}.'_'.$row{last_name}.'_'.$row{client_id};
  }
  else{
      echo "There was an error while fetching the row.<br/>";
  }
}

class ImgResizer {
  private $originalFile = '';
  public function __construct($originalFile = '') {
      $this -> originalFile = $originalFile;
  }
  public function resize($newWidth, $targetFile) {
      if (empty($newWidth) || empty($targetFile)) {
          return false;
      }
      $src = imagecreatefromjpeg($this -> originalFile);
      list($width, $height) = getimagesize($this -> originalFile);
      $newHeight = ($height / $width) * $newWidth;
      $tmp = imagecreatetruecolor($newWidth, $newHeight);
      imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
      if (file_exists($targetFile)) {
          unlink($targetFile);
      }
      imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 – 100 for output image quality with 100 being the most luxurious
  }
}

?>

Here is the snippet from upload_photo.php

echo '<form enctype="multipart/form-data" action="uploader.php" method="POST">';
echo '<tr>';
//echo "<td colspan='2'>".$_GET['text']."</td>";
echo '</tr>';
echo '<tr align="center">';
echo '<td colspan="2">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
        Choose a file to upload: <input name="uploadedfile" type="file" accept="image/*"/><br />
        <input type="submit" value="Upload File" />
      </form>';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:55:19+00:00Added an answer on June 14, 2026 at 10:55 am

    That probably means that the upload went through okay – the file is uploaded to your temp directory – but the file could not be moved to the destination you have set.

    You should double-check the path you are moving the file to and make sure that the web user (apache, www or whatever) has permissions to write to that directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a simple form to upload 5 files: <form enctype=multipart/form-data action=openaccount.php method=post> <h4>Proof
Im submitting Data to a php file via AJAX using POST. It worked fine
I am using POST as discussed here to upload an image and some parameters
I would like to upload a file from android device to server using php.
I am using this form: <FORM action=testimage1.php method=post> <div style=font:bold 10px arial,serif; >Product Name*</div>
I have made a form validation using ajax post method. But i got the
I am getting the following error, using jQuery POST method in Firefox. Could not
I'm submitting a form using an ajax request (POST method), and checking the HTTP
How to send an http request with either post/get method using javascript as an
$.ajax({ url: /cgi-bin/stats.exe, method: post, async: false, data: { refresh: a41 } }); Using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.