PHP警告:imagejpeg():无法打开'.Project / events / timepass.jpg'进行写入:第35行的./Project/upload/thumbnal.php中没有此类文件或目录
代码..
<?php
// open the directory
$pathToImages="./Project/upload/original/";
$dir = opendir($pathToImages);
// loop through it, looking for any/all JPG files:
while (false !== ($fname = readdir( $dir )))
{
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if ( strtolower($info['extension']) == 'jpg')
{
// echo "Creating thumbnail for {$fname} <br />";
// load image and get image size
$image_size=getimagesize( "{$pathToImages}{$fname}");
$image_width=$image_size[0];
$image_height=$image_size[1];
$new_size=($image_width+$image_height)/($image_width*($image_height/80));
$new_width=$image_width*$new_size;
$new_height=$image_height*$new_size;
$new_image=imagecreatetruecolor($new_width,$new_height);
$old_image=imagecreatefromjpeg("{$pathToImages}{$fname}");
imagecopyresized($new_image,$old_image,0,0,0,0,$new_width,$new_height,$image_width,$image_height);
$pathToThumbs="./Project/events/$fname";
imagejpeg($new_image,$pathToThumbs);
// save thumbnail into a file
}
}
// close the directory
closedir( $dir );
?>
当我将我的数据从localhost传输到实时服务器FTP时,我收到此错误。我在google上搜索了一些已经建议将目录的属性更改为777.i确实没有使用相同的警告。请告诉我应该在哪里制作更改以使这些代码有效。
答案 0 :(得分:0)
您是否将新图像传输到远程服务器?
服务器的路径在哪里? Like "--IP TO SERVER--/Project/events/"
问题是,在本地计算机上找不到您编写的路径。
<强>更新强>
要将图像上传到FTP服务器,请查看此示例:
<?php
$file = 'somefile.txt';
$ftp_server = "ftp.example.com";
// Connection
$conn_id = ftp_connect($ftp_server);
// Login with user and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// File upload
// $remote_file is the filename on the server
// $file the filename on your local machine
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "success\n";
} else {
echo "error\n";
}
// Close connection
ftp_close($conn_id);
?>
答案 1 :(得分:0)
通常,当您遇到此类问题时,请确保路径存在,并且您尝试上传图像的用户具有该路径的必要权限。