Jump to content

[SOLVED] file upload


chriscloyd

Recommended Posts

this is my script might be long but all of it works until it gets to the new part where it uploads it wont up load it says folder is not set to 777 but it is i did set it

<?php
session_start();
$allowed_filetypes = array('.jpg','.gif','.bmp','.png');
$max_filesize = 524288;
$upload_path = '/myphotos';
$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
echo "Checking Theres A Photo: ";
ob_start();
for($i=1;$i<11;$i++) {
echo $i.' ';
if ($i == 10) {
	if ($filename != NULL) {
		$_SESSION['cpcerror'] = 0;
		echo '&#10004;';
	} else {
		$_SESSION['cpcerror'] = 1;
		echo '&#10006;';
	}
}
ob_flush();
flush();
usleep(500000);
ob_end_flush();
}
if ($_SESSION['cpcerror'] == 0) {
unset($_SESSION['cpcerror']);
echo '<br>Checking Photo Type: ';
ob_start();
for($i=1;$i<11;$i++) {
	echo $i.' ';
	if ($i == 10) {
		if(in_array($ext,$allowed_filetypes)) {
			$_SESSION['cpcerror'] = 0;
			echo '&#10004;';
		} else {
			$_SESSION['cpcerror'] = 1;
			echo '&#10006;';
		}
	}
	ob_flush();
	flush();
	usleep(500000);
	ob_end_flush();
}
}
if ($_SESSION['cpcerror'] == 0) {
unset($_SESSION['cpcerror']);
echo '<br>Checking Photo Size: ';
ob_start();
for($i=1;$i<11;$i++) {
	echo $i.' ';
	if ($i == 10) {
		if(filesize($_FILES['userfile']['tmp_name']) < $max_filesize) {
			$_SESSION['cpcerror'] = 0;
			echo '&#10004;';
		} else {
			$_SESSION['cpcerror'] = 1;
			echo '&#10006;';
		}
	}
	ob_flush();
	flush();
	usleep(500000);
	ob_end_flush();
}
}
if ($_SESSION['cpcerror'] == 0) {
unset($_SESSION['cpcerror']);
echo '<br>Generating New File Name: ';
ob_start();
for($i=1;$i<11;$i++) {
	echo $i.' ';
	if ($i == 10) {
		$random = rand(5768,983468);
		$new_name = $random.'_'.$filename;
		echo '&#10004;';
		$_SESSION['cpcerror'] = 0;
	}
	ob_flush();
	flush();
	usleep(500000);
	ob_end_flush();
}
}
if ($_SESSION['cpcerror'] == 0) {
unset($_SESSION['cpcerror']);
echo '<br>Uploading Photo To <a href="../index.php?p=photos">My Photos</a>: ';
ob_start();
for($i=1;$i<11;$i++) {
	echo $i.' ';
	if ($i == 10) {
		if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path.'/'.$new_name)) {
			echo '&#10004;';
		} else {
			 if(!is_writable($upload_path)) {
      				echo 'You cannot upload to the specified directory, please CHMOD it to 777.';
  			 }
			echo '&#10006;';
		}
	}
	ob_flush();
	flush();
	usleep(500000);
	ob_end_flush();
}
}

if ($_SESSION['cpcerror'] == 1) {
echo 'Could No Upload File Try Again';
header("Location: index.php");
}
?>

Link to comment
Share on other sites

Checking Theres A Photo: 1 2

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

3

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

4

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

5

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

6

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

7

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

8

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

9

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

10 ✔

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 23

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 26

 

Checking Photo Type: 1 2

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

3

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

4

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

5

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

6

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

7

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

8

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

9

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

10 ✔

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 43

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 46

 

Checking Photo Size: 1 2

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

3

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

4

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

5

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

6

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

7

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

8

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

9

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

10 ✔

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 64

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 67

 

Uploading Photo To My Photos: 1 2

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

3

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

4

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

5

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

6

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

7

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

8

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

9

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

10 You cannot upload to the specified directory, please CHMOD it to 777.✖

Notice: ob_flush() [ref.outcontrol]: failed to flush buffer. No buffer to flush. in /home/cpc/public_html/admin/upload_photo.php on line 86

 

Notice: ob_end_flush() [ref.outcontrol]: failed to delete and flush buffer. No buffer to delete or flush. in /home/cpc/public_html/admin/upload_photo.php on line 89

 

Notice: Undefined index: cpcerror in /home/cpc/public_html/admin/upload_photo.php on line 93

Link to comment
Share on other sites

'Generating New File Name: ' is not showing as well. I believe that all the usage of output buffering is dropping output, including relevant errors.

 

Start with the basics and get it to work first, without all the BS of looping 1...10 and the output buffering. The entire script probably executes in a few 100 milliseconds and doing all that might look neat but is probably covering up what is really happening.

Link to comment
Share on other sites

If you actually try your current online code, you get the following -

 

Warning: move_uploaded_file(/myphotos/somefile.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/cpc/public_html/admin/upload_photo.php on line 77

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpc6OYJp' to '/myphotos/somefile.jpg' in

 

Your posted code in this thread is not your actual code because the Generating New File Name:/$new_name logic is not present in the actual code. I'm not going to guess why the code you have been trying has not output the above two errors.

 

Those two error messages mean that the folder /myphotos does not exist in the root of the hard disk, which is why the is_writable() is returning a FALSE value as well.

 

If the myphotos folder is actually within your web document root folder, then you need to form the path correctly. A leading slash / on a file system path refers to the root of the hard disk not your document root.

Link to comment
Share on other sites

did it normal like this

<?php
   // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png');
      $max_filesize = 524288;
      $upload_path = 'myphotos/';

   $filename = $_FILES['userfile']['name'];
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');

   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.';

?>

 

and got this error

There was an error during the file upload. Please try again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.