I have the following script, which is the first part of a page that receives image uploads. However, it is missing the opening curly brace and I don’t know where to put it so it is correct syntax. (The closing curly brace ends just before “else.”) Where do I put the first curly brace?Evidently I’m not beginning the script correctly.
where’s the if that starts it? Do you have all the code for sure?
Is this file perhaps included and there’s another before it which may have the proper start of the if statement
though if there is, I personally would hunt the developer of that codebase down, tie him/her to a set of railroad tracks, and perform some sort of horrendous torture (wet noodle slapping?) for coming up with such a bad design.
[04-Mar-2014 16:11:53 America/Denver] PHP Warning: move_uploaded_file(uploads/1393974863673.jpg): failed to open stream: No such file or directory in /home2/stevehus/public_html/uploads/upload.php on line 35
[04-Mar-2014 16:11:53 America/Denver] PHP Warning: move_uploaded_file(): Unable to move '/var/tmp/php0vy3Rj' to 'uploads/1393974863673.jpg' in /home2/stevehus/public_html/uploads/upload.php on line 35
The URLs are actually correct, so I don’t understand the problem; files and folders are as shown in the errors.
My php.ini changes:
file_uploads must be set to on:
file_uploads = On
upload_tmp_dir value must be set to where uploads will be placed:
upload_tmp_dir = var/tmp/
upload_max_filesize dictates how large a file can be sent
upload_max_filesize = 10M
File is currently:
<?php
// File types allowed on upload:
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
// Examine if file is indeed an image:
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0) // if file is not an allowed image type, show error:
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else // if file is valid, upload to tmp folder and give information about the file:
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp filename: " . $_FILES["file"]["tmp_name"] . "<br>";
/*
CUSTOMIZE: THE NAME OF THE FOLDER THAT THIS PHP UPLOAD SCRIPT RESIDES IN.
*/
if (file_exists("home2/stevehus/public_html/uploads/" . $_FILES["file"]["name"]))
{ // If file exists with that name:
echo $_FILES["file"]["name"] . " already exists. ";
}
else // if file name is unique, move from tmp folder to named folder
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . $_FILES["file"]["name"]);
/*
CUSTOMIZE: THE NAME OF THE FOLDER THAT THIS PHP UPLOAD SCRIPT RESIDES IN.
*/
echo "Stored in: " . "home2/stevehus/public_html/uploads/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>